The C++ rvalue Lifetime Disaster
summary
C++ lets rvalues bind to const&, which silently lies about lifetime and produces real dangling references and hard-to-find memory corruption in deployed code. Mitigations shown: a library-only autocrf macro that decays rvalues into owned values when needed, deleting rvalue-qualified accessors, and a custom common_reference wrapper to avoid spurious copies. A hypothetical pragma for new binding rules is proposed to flip binding direction in new code, but practical fix today is the macro-based, source-level workaround.
AI-written summary · about
chapters (28)
- 0:00Introduction
- 0:47Rvalue Lifetime
- 4:12Named Return Value Optimization
- 6:02No Named Return Value Optimization
- 6:50A Special Case
- 8:05Recommendations
- 8:39Temporary Lifetime Extension
- 9:07Generic Code
- 9:35Lifetime Extension
- 10:39Example
- 14:20The problem
- 15:31The solution
- 17:04Declaration type
- 17:25Autocrf
- 17:50Autocrf const
- 18:56Autocrf rvalue
- 19:24Accessors
- 21:27C
- 25:57What C does
- 27:40We made a mess
- 27:59Warning
- 28:11Requirements
- 28:40Reference Binding
- 30:38Trying it out
- 32:12Impact on the standard library
- 33:01Mitigations
- 33:36Member Accessors
- 35:39Conclusion
related talks
47mThe C++ rvalue Lifetime Disaster
01h 01mSurprises in Object Lifetime
58mAn (In-)Complete Guide to C++ Object Lifetimes
05mReducing immediate dangling?
19mC++ Const Correctness Refresher
58mModern C++ Design (part 2 of 2)
01h 39m“Leak-Freedom in C++... By Default.”
01h 02mUnderstanding C++ Value Categories: lvalue, rvalue, xvalue, std::move, std::forward & Best Practices
