Debian Codegraph @

libcxx/test/std/atomics/atomics.ref/assign.pass.cpp

raw
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 // T operator=(T) 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 TestAssign {
24 void operator()() const {
25 {
26 T x(T(1));
27 std::atomic_ref<T> const a(x);
28
29 std::same_as<T> decltype(auto) y = (a = T(2));
30 assert(y == T(2));
31 assert(x == T(2));
32
33 ASSERT_NOEXCEPT(a = T(0));
34 static_assert(std::is_nothrow_assignable_v<std::atomic_ref<T>, T>);
35
36 static_assert(!std::is_copy_assignable_v<std::atomic_ref<T>>);
37 }
38
39 {
40 auto assign = [](std::atomic_ref<T> const& y, T, T new_val) { y = new_val; };
41 auto load = [](std::atomic_ref<T> const& y) { return y.load(); };
42 test_seq_cst<T>(assign, load);
43 }
44 }
45 };
46
47 int main(int, char**) {
48 TestEachAtomicType<TestAssign>()();
49 return 0;
50 }