A Deep Dive Into C++ Object Lifetimes
summary
Detailed survey of where C++ lifetimes actually start and end, with concrete rules and recent changes: std::start_lifetime_as for safely claiming malloc/mmap bytes, std::launder and std::bit_cast limitations for provenance and strict-aliasing, placement new plus explicit destructor semantics, temporary-lifetime extension quirks, and the C++20 implicit-object-creation fix (and C++26’s move from UB to erroneous for uninitialized reads). Plenty of counterexamples showing when pointer/register optimizations break, where unions and const heap objects bite, and which compiler assumptions cause real bugs.
AI-written summary · about
chapters (11)
- 0:00Introduction to object lifetimes
- 8:28Storage duration and lifetime basics
- 16:33New, delete and placement new
- 23:59Temporary objects and lifetime extension
- 36:25Implicit object creation
- 46:00Object reuse and transparent replacement
- 57:41Pointer provenance and laundering
- 1:06:34Type punning rules
- 1:13:13Invalid pointers and zombie pointers
- 1:19:33Guidelines and conclusion
- 1:28:04Q&A and closing
related talks
01h 00mType punning in modern C++
01h 39m“Thoughts on a more powerful and simpler C++ (5 of N)”
59mThe Best Parts of C++
01h 03mC++ Trivial Relocation Through Time
37mMemory Safety Everywhere with Both Rust and Carbon
06mv.~uint32_t();
01h 05mType Punning in C++17: Avoiding Pun-defined Behavior
42mThe Nightmare of Move Semantics for Trivial C++ Classes
