World Congress 2023 • Aug 11, 2023

The C++ rvalue lifetime disaster

Arno Schoedl

Are C++ rvalues silently causing dangling references? This fundamental language flaw strips rvalue context, creating "rvalue amnesia." Learn how to protect your codebase using practical library-level mitigations.

Pause
Mute Enter Fullscreen
#1 about 2 min

The origin of r-value references for copy avoidance

Moving objects directly using r-value references eliminates the need for expensive memory reallocations.

#2 about 2 min

Managing object lifetimes with r-value references

R-value references act as signals for ephemeral objects to prevent dangling references in container adapters.

#3 about 4 min

Flaws in temporary lifetime extension with r-values

The legacy temporary lifetime extension fails to recognize r-value references, causing silent dangling references.

#4 about 3 min

Using a smart macro to replace temporary lifetime extension

A custom macro dynamically binds expressions as values or references to prevent lifetime issues automatically.

#5 about 3 min

Silent failures when accessing members of r-values

Wrapping private members in public accessors silently transforms safe r-values into dangerous l-value references.

#6 about 2 min

How common reference triggers r-value amnesia

Mixing r-values and l-values in ternary operators forces the compiler to drop r-value characteristics completely.

#7 about 2 min

Reevaluating reference binding rules to fix lifetimes

Reversing the allowable binding directions prevents developers from making impossible lifetime and mutability promises.

#8 about 4 min

Implementing new binding rules with migration pragmas

A proposed compiler pragma allows codebases to transition safely from old to new reference binding rules.

#9 about 3 min

Practical mitigations for current reference binding issues

Re-implementing common reference and the ternary operator with macros prevents unnecessary object copying in existing compilers.

#10 about 3 min

Managing language complexity with strong coding guidelines

Adopting strict internal standards helps developers navigate language idiosyncrasies and write expressive code safely.

Matching moments

2:15 min

Risks of temporary lifetime extensions via implicit references

Jonathan Müller Jonathan Müller · World Congress 2024

13:57 min

History of C++ technical debt and language design

Stefan Baumgartner · LIVE

5:20 min

Managing memory and resources with deterministic object destruction

Andreas Fertig · World Congress 2021

1:51 min

Eliminating null pointer references with structural safety

Patrick Koss Patrick Koss · World Congress 2024

3:32 min

Clarifying best practice patterns during structural syntax tool discussions

Jens Claes · World Congress 2023

7:45 min

Bridging hardware manipulation and high-level object abstractions

Andreas Fertig · World Congress 2021