Arno Schoedl

The C++ rvalue lifetime disaster

Why do common C++ features like `std::min` and the ternary operator create dangling references? This talk reveals a fundamental language flaw and how to fix it.

The C++ rvalue lifetime disaster
#1about 3 minutes

The dual role of rvalue references in C++

Rvalue references were introduced for move semantics to avoid copies but are also used to manage the lifetime of temporary objects.

#2about 6 minutes

Why temporary lifetime extension fails in modern C++

The pre-C++11 feature for extending temporary object lifetimes does not work correctly with rvalue references, necessitating a custom macro to create a value or reference based on expression type.

#3about 6 minutes

How accessor methods cause rvalue amnesia

Standard accessor methods returning a const lvalue reference incorrectly bind to rvalues, losing critical lifetime information and leading to dangling references.

#4about 4 minutes

A proposal for fixing C++ reference binding rules

A proposed language fix using pragmas would introduce new, safer reference binding rules to prevent short-lived rvalues from binding to long-lived lvalue references.

#5about 3 minutes

Practical mitigations for rvalue lifetime issues today

Use custom macros to manage variable lifetimes, guard member accessors, and implement a correct ternary operator to work around the language's flawed binding rules.

#6about 1 minute

Managing C++ complexity with strong coding guidelines

The best way to manage the growing complexity of C++ is to establish strong internal coding guidelines and use custom libraries to standardize code patterns.

Related jobs
Jobs that call for the skills explored in this talk.

Featured Partners

Related Articles

View all articles
CH
Chris Heilmann
All the videos of Halfstack London 2024!
Last month was Halfstack London, a conference about the web, JavaScript and half a dozen other things. We were there to deliver a talk, but also to record all the sessions and we're happy to share them with you. It took a bit as we had to wait for th...
All the videos of Halfstack London 2024!
DC
Daniel Cranney
Dev Digest 193: Vibe Coding Honeymoon, NaN and the End of Interviews
Inside last week’s Dev Digest 193 . 🛰️ A satellite of doom 🤔 Why em-dashes? 😔 Vibe coding Honeymoon is over 🖼️ GenAI image showdown 🔥 Dangers of firewalls and VPNs 👨‍💼 AI broke interviews 🦉 A LinkedIn wisdom generator 🗞️ Join over 150,000 developers...
Dev Digest 193: Vibe Coding Honeymoon, NaN and the End of Interviews
BR
Benjamin Ruschin
What Developers Really Need to Create Great Code Demos
Every developer on earth has, at some point, had another developer to thank for a breakthrough, a success, an aha moment they wouldn’t have had without coming across that blog post, that open-source contribution, that reply on socials or that humble ...
What Developers Really Need to Create Great Code Demos
DC
Daniel Cranney
Dev Digest 188: CfP time, the risks of NPM and IKEA algorithms
Inside last week’s Dev Digest 188 . 🤖 GitHub Copilot CLI is now in public review 💻 Microsoft is bringing ‘vibe working’ to office apps 🎣 Attackers abuse AI tools to generate captchas in fishing attacks ⚠️ When LLMs autonomously attack 🧠 Common cause...
Dev Digest 188: CfP time, the risks of NPM and IKEA algorithms

From learning to earning

Jobs that call for the skills explored in this talk.

Rust and GoLang

Rust and GoLang

NHe4a GmbH
Karlsruhe, Germany

Remote
55-65K
Intermediate
Senior
Go
Rust
Techlead C++

Techlead C++

REDLAB
Paris, France

QT
C++
Software Architecture
C++ Software Engineer

C++ Software Engineer

Rebel Talent
Municipality of San Cristóbal de La Laguna, Spain

QT
C++
GIT
CMake
DevOps
+3