What is the 'Static Initialization Order Fiasco' and how can it be avoided?
Last updated
The fiasco occurs when a global static in one translation unit depends on a global in another, but cross-TU initialization order is unspecified, so the dependency may be used before construction.
Fix it with Construct On First Use: a function returning a reference to a
staticlocal, initialized on first call (thread-safe since C++11).Also prefer
constexpr/constant-initialized globals and minimize global mutable state.