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 // UNSUPPORTED: libcpp-has-no-threads
10 
11 // This test verifies behavior specified by [atomics.types.operations.req]/21:
12 //
13 //     When only one memory_order argument is supplied, the value of success is
14 //     order, and the value of failure is order except that a value of
15 //     memory_order_acq_rel shall be replaced by the value memory_order_acquire
16 //     and a value of memory_order_release shall be replaced by the value
17 //     memory_order_relaxed.
18 //
19 // Clang's atomic intrinsics do this for us, but GCC's do not. We don't actually
20 // have visibility to see what these memory orders are lowered to, but we can at
21 // least check that they are lowered at all (otherwise there is a compile
22 // failure with GCC).
23 
24 #include <atomic>
25 
26 int main(int, char**) {
27     std::atomic<int> i;
28     volatile std::atomic<int> v;
29     int exp = 0;
30 
31     i.compare_exchange_weak(exp, 0, std::memory_order_acq_rel);
32     i.compare_exchange_weak(exp, 0, std::memory_order_release);
33     i.compare_exchange_strong(exp, 0, std::memory_order_acq_rel);
34     i.compare_exchange_strong(exp, 0, std::memory_order_release);
35 
36     v.compare_exchange_weak(exp, 0, std::memory_order_acq_rel);
37     v.compare_exchange_weak(exp, 0, std::memory_order_release);
38     v.compare_exchange_strong(exp, 0, std::memory_order_acq_rel);
39     v.compare_exchange_strong(exp, 0, std::memory_order_release);
40 
41     return 0;
42 }
43