1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <atomic> 10 11 // struct atomic_flag 12 13 // TESTING EXTENSION atomic_flag(bool) 14 15 #include <atomic> 16 #include <cassert> 17 18 #include "test_macros.h" 19 20 #if TEST_STD_VER >= 11 21 // Ensure that static initialization happens; this is PR#37226 22 extern std::atomic_flag global; XX23struct X { X() { global.test_and_set(); }}; 24 X x; 25 std::atomic_flag global{false}; 26 #endif 27 main(int,char **)28int main(int, char**) 29 { 30 #if TEST_STD_VER >= 11 31 assert(global.test_and_set() == 1); 32 #endif 33 { 34 std::atomic_flag f(false); 35 assert(f.test_and_set() == 0); 36 } 37 { 38 std::atomic_flag f(true); 39 assert(f.test_and_set() == 1); 40 } 41 42 return 0; 43 } 44