The C++ rvalue Lifetime Disaster
summary
C++ lets const& silently bind rvalues and a prvalue bound through a function loses lifetime extension, causing real dangling references and memory corruption in production code. Evidence: std::min/std::max and accessor returns turn temporaries into long-lived const&; passing a prvalue through forwarding breaks lifetime extension. Built mitigations are library-only: an autoCRef macro that decays temporaries to values, a custom common_reference and ternary wrapper, and deleted rvalue accessor overloads; these mitigations are used successfully, while a full language fix remains unimplemented.
AI-written summary · about
chapters (10)
- 0:00Start
- 5:39Rvalue References for Moving - Pitfalls
- 12:19Temporary Lifetime Extension vs. Rvalues
- 22:55C++ Rvalue Amnesia
- 26:04Conditional Operator Afraid of Rvalue Amnesia
- 27:27C++20 common_reference Not Afraid
- 29:30Promises of References
- 34:19Reference Declarations (2)
- 36:14Impact on Standard Library
- 39:21Summary
related talks
37mThe C++ rvalue Lifetime Disaster
01h 01mSurprises in Object Lifetime
05mReducing immediate dangling?
58mAn (In-)Complete Guide to C++ Object Lifetimes
01h 36mC++ Standard Views
19mC++ Const Correctness Refresher
01h 02mUnderstanding C++ Value Categories: lvalue, rvalue, xvalue, std::move, std::forward & Best Practices
01h 21mAn (In-)Complete Guide to C++ Object Lifetimes
