1 | // |
2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
3 | // See https://llvm.org/LICENSE.txt for license information. |
4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
5 | // |
6 | //===----------------------------------------------------------------------===// |
7 | |
8 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
9 | // XFAIL: !has-64-bit-atomics |
10 | // XFAIL: !has-1024-bit-atomics |
11 | |
12 | // void store(T, memory_order = memory_order::seq_cst) const noexcept; |
13 | |
14 | #include <atomic> |
15 | #include <cassert> |
16 | #include <type_traits> |
17 | |
18 | #include "atomic_helpers.h" |
19 | #include "test_helper.h" |
20 | #include "test_macros.h" |
21 | |
22 | template <typename T> |
23 | struct TestStore { |
24 | void operator()() const { |
25 | T x(T(1)); |
26 | std::atomic_ref<T> const a(x); |
27 | |
28 | a.store(T(2)); |
29 | assert(x == T(2)); |
30 | ASSERT_NOEXCEPT(a.store(T(1))); |
31 | |
32 | a.store(T(3), std::memory_order_seq_cst); |
33 | assert(x == T(3)); |
34 | ASSERT_NOEXCEPT(a.store(T(0), std::memory_order_seq_cst)); |
35 | |
36 | // TODO memory_order::relaxed |
37 | |
38 | // memory_order::seq_cst |
39 | { |
40 | auto store_no_arg = [](std::atomic_ref<T> const& y, T, T new_val) { y.store(new_val); }; |
41 | auto store_with_order = [](std::atomic_ref<T> const& y, T, T new_val) { |
42 | y.store(new_val, std::memory_order::seq_cst); |
43 | }; |
44 | auto load = [](std::atomic_ref<T> const& y) { return y.load(); }; |
45 | test_seq_cst<T>(store_no_arg, load); |
46 | test_seq_cst<T>(store_with_order, load); |
47 | } |
48 | |
49 | // memory_order::release |
50 | { |
51 | auto store = [](std::atomic_ref<T> const& y, T, T new_val) { y.store(new_val, std::memory_order::release); }; |
52 | auto load = [](std::atomic_ref<T> const& y) { return y.load(std::memory_order::acquire); }; |
53 | test_acquire_release<T>(store, load); |
54 | } |
55 | } |
56 | }; |
57 | |
58 | int main(int, char**) { |
59 | TestEachAtomicType<TestStore>()(); |
60 | return 0; |
61 | } |
62 | |