| 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 <concepts> |
| 17 | #include <type_traits> |
| 18 | |
| 19 | #include "atomic_helpers.h" |
| 20 | #include "test_helper.h" |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | template <typename T> |
| 24 | struct TestAssign { |
| 25 | void operator()() const { |
| 26 | { |
| 27 | T x(T(1)); |
| 28 | std::atomic_ref<T> const a(x); |
| 29 | |
| 30 | std::same_as<T> decltype(auto) y = (a = T(2)); |
| 31 | assert(y == T(2)); |
| 32 | assert(x == T(2)); |
| 33 | |
| 34 | ASSERT_NOEXCEPT(a = T(0)); |
| 35 | static_assert(std::is_nothrow_assignable_v<std::atomic_ref<T>, T>); |
| 36 | |
| 37 | static_assert(!std::is_copy_assignable_v<std::atomic_ref<T>>); |
| 38 | } |
| 39 | |
| 40 | { |
| 41 | auto assign = [](std::atomic_ref<T> const& y, T, T new_val) { y = new_val; }; |
| 42 | auto load = [](std::atomic_ref<T> const& y) { return y.load(); }; |
| 43 | test_seq_cst<T>(assign, load); |
| 44 | } |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | int main(int, char**) { |
| 49 | TestEachAtomicType<TestAssign>()(); |
| 50 | return 0; |
| 51 | } |
| 52 | |