Initialization, Shutdown, and constexpr
summary
Explains why global objects fail at startup or shutdown by walking the actual rules: four storage durations, static initialization order fiasco, distinction of zero vs constant vs dynamic initialization, and when lifetime begins or ends for class types. Recommends concrete fixes: prefer constexpr globals or ABSL_CONST_INIT where available, use thread-safe function-local static wrappers that allocate on the heap to avoid destructor races, enable compiler warnings like “warn global constructors,” or call std::quick_exit when safe.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 0:23Why initialization is hard
- 3:39Storage duration explained
- 8:18Static initialization rules
- 9:22Static initialization order fiasco
- 12:12Function static locals
- 13:15Zero vs constant initialization
- 16:11Constant initialization in C++11
- 19:04Making globals safe with constexpr
- 23:35Object lifetime vs storage duration
- 25:18Trivially constructible types
- 28:07Global object lifetime graph
- 32:02Global destructor rules
- 36:12Destruction order guarantees
- 40:51Static local thread safety
- 41:11Advanced initialization corner cases
- 43:59Inline variables in C++17
- 46:26Safe global patterns
- 48:40Q&A session
related talks
55mSafe Static Initialisation & Clean Up in Libraries
01h 21mAn (In-)Complete Guide to C++ Object Lifetimes
58mAn (In-)Complete Guide to C++ Object Lifetimes
11mLightning talk: Manual (de)initialization A Rust and C++
01h 00mHow To Use `constexpr` In C++23
32mCute C++ Tricks, Part 2 of N: More code you should learn from and never write
54mTypical C++, But Why?
19mC++ Const Correctness Refresher
