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// bool atomic_flag_test_and_set(volatile atomic_flag*);
14// bool atomic_flag_test_and_set(atomic_flag*);
15
16#include <atomic>
17#include <cassert>
18
19#include "test_macros.h"
20
21int main(int, char**)
22{
23 {
24 std::atomic_flag f;
25 f.clear();
26 assert(std::atomic_flag_test_and_set(&f) == 0);
27 assert(f.test_and_set() == 1);
28 }
29 {
30 volatile std::atomic_flag f;
31 f.clear();
32 assert(std::atomic_flag_test_and_set(&f) == 0);
33 assert(f.test_and_set() == 1);
34 }
35
36 return 0;
37}
38

source code of libcxx/test/std/atomics/atomics.flag/atomic_flag_test_and_set.pass.cpp