From 07a9ff8d1e72e7df0917f1fd36167d09088c3b60 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 4 Apr 2019 00:11:21 +0000 Subject: [PATCH] Make ManagedStatic constexpr constructible Apparently it needs member initializers so that it can be constructed in a constexpr context. I explained my investigation of this in PR41367. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357655 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ManagedStatic.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/include/llvm/Support/ManagedStatic.h b/include/llvm/Support/ManagedStatic.h index 441f24e05af..ebf9bba5c22 100644 --- a/include/llvm/Support/ManagedStatic.h +++ b/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; } -- 2.50.1