An (In-)Complete Guide to C++ Object Lifetimes
summary
Claims the C++ standard has mistakes and walks through concrete rules: when declarations, new/placement new, memcpy/bit_cast, or std::start_lifetime_as actually begin lifetimes; how temporary lifetime extension and range-for rules extend temporaries; why pointer provenance (not just address) makes some pointer arithmetic UB; when std::launder fixes provenance after placement new; memcpy/bit_cast as the safe type‑punning path; and that C++26 downgrades some UB to erroneous to curb optimizations. Practical advice: prefer placement new/start_lifetime_as or unions, and avoid relying on implicit object creation.
AI-written summary · about
chapters (11)
- 0:00C++ object lifetimes intro
- 6:22Variable declarations storage
- 11:35Dynamic allocation new/delete
- 12:36Temporary objects lifetime
- 18:08Placement new manual control
- 27:57Replacement transparency
- 33:12Implicit object creation
- 37:59Pointer provenance
- 44:58Type punning reinterpret_cast
- 51:22Type punning techniques
- 55:18Guidelines summary
related talks
01h 21mAn (In-)Complete Guide to C++ Object Lifetimes
49mC++: Objects, their lifetime and pointers
04mLightning Talk: Now in Our Lifetimes Cpp
59mA Tour of C++ Recognised User Type Categories
06mAre We There Yet?
01h 01mSurprises in Object Lifetime
37mThe C++ rvalue Lifetime Disaster
01h 08mImplementing the C++ Core Guidelines’ Lifetime Safety Profile in Clang
