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 | // 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 TestConvert { |
24 | void operator()() const { |
25 | T x(T(1)); |
26 | |
27 | T copy = x; |
28 | std::atomic_ref<T> const a(copy); |
29 | |
30 | T converted = a; |
31 | assert(converted == x); |
32 | |
33 | ASSERT_NOEXCEPT(T(a)); |
34 | static_assert(std::is_nothrow_convertible_v<std::atomic_ref<T>, T>); |
35 | |
36 | auto store = [](std::atomic_ref<T> const& y, T, T new_val) { y.store(new_val); }; |
37 | auto load = [](std::atomic_ref<T> const& y) { return static_cast<T>(y); }; |
38 | test_seq_cst<T>(store, load); |
39 | } |
40 | }; |
41 | |
42 | int main(int, char**) { |
43 | TestEachAtomicType<TestConvert>()(); |
44 | return 0; |
45 | } |
46 | |