libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

init_bool.pass.cpp (1013B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // UNSUPPORTED: libcpp-has-no-threads
     11 
     12 // <atomic>
     13 
     14 // struct atomic_flag
     15 
     16 // TESTING EXTENSION atomic_flag(bool)
     17 
     18 #include <atomic>
     19 #include <cassert>
     20 
     21 #include "test_macros.h"
     22 
     23 #if TEST_STD_VER >= 11
     24 // Ensure that static initialization happens; this is PR#37226
     25 extern std::atomic_flag global;
     26 struct X { X() { global.test_and_set(); }};
     27 X x;
     28 std::atomic_flag global = ATOMIC_FLAG_INIT;
     29 #endif
     30 
     31 int main()
     32 {
     33 #if TEST_STD_VER >= 11
     34     assert(global.test_and_set() == 1);
     35 #endif
     36     {
     37         std::atomic_flag f(false);
     38         assert(f.test_and_set() == 0);
     39     }
     40     {
     41         std::atomic_flag f(true);
     42         assert(f.test_and_set() == 1);
     43     }
     44 }