]> granicus.if.org Git - llvm/commitdiff
Make ManagedStatic constexpr constructible
authorReid Kleckner <rnk@google.com>
Thu, 4 Apr 2019 00:11:21 +0000 (00:11 +0000)
committerReid Kleckner <rnk@google.com>
Thu, 4 Apr 2019 00:11:21 +0000 (00:11 +0000)
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

index 441f24e05afc589e597aa288737e060edcdd0699..ebf9bba5c22f4262ab2b8cd985b0f334890f6e38 100644 (file)
@@ -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<void *> Ptr;
-  mutable void (*DeleterFn)(void*);
-  mutable const ManagedStaticBase *Next;
+  mutable std::atomic<void *> 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; }