diff --git a/llvm/include/llvm/Support/ManagedStatic.h b/llvm/include/llvm/Support/ManagedStatic.h index 441f24e05afc..ebf9bba5c22f 100644 --- a/llvm/include/llvm/Support/ManagedStatic.h +++ b/llvm/include/llvm/Support/ManagedStatic.h @@ -37,13 +37,18 @@ class ManagedStaticBase { protected: // This should only be used as a static variable, which guarantees that this // will be zero initialized. - mutable std::atomic Ptr; - mutable void (*DeleterFn)(void*); - mutable const ManagedStaticBase *Next; + mutable std::atomic Ptr{nullptr}; + mutable void (*DeleterFn)(void *) = nullptr; + mutable const ManagedStaticBase *Next = nullptr; void RegisterManagedStatic(void *(*creator)(), void (*deleter)(void*)) const; public: + /// ManagedStaticBase must be constexpr constructed so that they can be + /// accessed and constructed lazily during dynamic initilization of other + /// global variables, such as cl::opt command line flags. + constexpr ManagedStaticBase() = default; + /// isConstructed - Return true if this object has not been created yet. bool isConstructed() const { return Ptr != nullptr; }