[llvm] r357716 - Appease STLs where std::atomic<void*> lacks a constexpr default ctor

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 4 11:45:05 PDT 2019


Author: rnk
Date: Thu Apr  4 11:45:05 2019
New Revision: 357716

URL: http://llvm.org/viewvc/llvm-project?rev=357716&view=rev
Log:
Appease STLs where std::atomic<void*> lacks a constexpr default ctor

MSVC 2019 casts the pointer to a pointer-sized integer, which is a
reinterpret_cast, which is invalid in a constexpr context, so I have to
remove the LLVM_REQUIRES_CONSTANT_INITIALIZATION annotation for now.

Modified:
    llvm/trunk/include/llvm/Support/ManagedStatic.h
    llvm/trunk/lib/Support/CommandLine.cpp

Modified: llvm/trunk/include/llvm/Support/ManagedStatic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ManagedStatic.h?rev=357716&r1=357715&r2=357716&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ManagedStatic.h (original)
+++ llvm/trunk/include/llvm/Support/ManagedStatic.h Thu Apr  4 11:45:05 2019
@@ -45,7 +45,7 @@ template <typename T, size_t N> struct o
 class ManagedStaticBase {
 protected:
 #ifndef LLVM_AVOID_CONSTEXPR_CTOR
-  mutable std::atomic<void *> Ptr;
+  mutable std::atomic<void *> Ptr{nullptr};
   mutable void (*DeleterFn)(void *) = nullptr;
   mutable const ManagedStaticBase *Next = nullptr;
 #else

Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=357716&r1=357715&r2=357716&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Thu Apr  4 11:45:05 2019
@@ -377,12 +377,10 @@ void OptionCategory::registerCategory()
 // that this ManagedStatic uses constant initailization and not dynamic
 // initialization because it is referenced from cl::opt constructors, which run
 // dynamically in an arbitrary order.
-LLVM_REQUIRE_CONSTANT_INITIALIZATION ManagedStatic<SubCommand>
-    llvm::cl::TopLevelSubCommand;
+ManagedStatic<SubCommand> llvm::cl::TopLevelSubCommand;
 
 // A special subcommand that can be used to put an option into all subcommands.
-LLVM_REQUIRE_CONSTANT_INITIALIZATION ManagedStatic<SubCommand>
-    llvm::cl::AllSubCommands;
+ManagedStatic<SubCommand> llvm::cl::AllSubCommands;
 
 void SubCommand::registerSubCommand() {
   GlobalParser->registerSubCommand(this);




More information about the llvm-commits mailing list