Fix static initialization of std::atomic_flag; Fixes PR#37226. Thanks to Ricky Zhou...
authorMarshall Clow <mclow.lists@gmail.com>
Wed, 25 Apr 2018 14:27:29 +0000 (14:27 +0000)
committerMarshall Clow <mclow.lists@gmail.com>
Wed, 25 Apr 2018 14:27:29 +0000 (14:27 +0000)
llvm-svn: 330828

libcxx/include/atomic
libcxx/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp

index f55e28f..34a2a58 100644 (file)
@@ -1741,7 +1741,7 @@ typedef struct atomic_flag
     atomic_flag() _NOEXCEPT : __a_() {}
 #endif // _LIBCPP_CXX03_LANG
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
 
 #ifndef _LIBCPP_CXX03_LANG
index d7b172c..1a8b320 100644 (file)
 #include <atomic>
 #include <cassert>
 
+ // Ensure that static initialization happens; this is PR#37226
+extern std::atomic_flag global;
+struct X { X() { global.test_and_set(); }};
+X x;
+std::atomic_flag global = ATOMIC_FLAG_INIT;
+
 int main()
 {
+    assert(global.test_and_set() == 1);
     {
         std::atomic_flag f(false);
         assert(f.test_and_set() == 0);