forked from OSchip/llvm-project
Fix static initialization of std::atomic_flag; Fixes PR#37226. Thanks to Ricky Zhou for the report and test case.
llvm-svn: 330828
This commit is contained in:
parent
d58bd8dc4a
commit
3df56fdd9b
|
@ -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
|
||||
|
|
|
@ -18,8 +18,15 @@
|
|||
#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);
|
||||
|
|
Loading…
Reference in New Issue