[llvm] r357655 - Make ManagedStatic constexpr constructible

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 3 17:11:21 PDT 2019


Author: rnk
Date: Wed Apr  3 17:11:21 2019
New Revision: 357655

URL: http://llvm.org/viewvc/llvm-project?rev=357655&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Support/ManagedStatic.h

Modified: llvm/trunk/include/llvm/Support/ManagedStatic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ManagedStatic.h?rev=357655&r1=357654&r2=357655&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ManagedStatic.h (original)
+++ llvm/trunk/include/llvm/Support/ManagedStatic.h Wed Apr  3 17:11:21 2019
@@ -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; }
 




More information about the llvm-commits mailing list