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 | // <atomic> |
10 | |
11 | // template <class T> |
12 | // struct atomic; |
13 | |
14 | // Make sure atomic<TriviallyCopyable> can be instantiated. |
15 | |
16 | #include <atomic> |
17 | #include <new> |
18 | #include <cassert> |
19 | #include <chrono> // for nanoseconds |
20 | |
21 | #include "test_macros.h" |
22 | |
23 | #ifndef TEST_HAS_NO_THREADS |
24 | # include <thread> // for thread_id |
25 | #endif |
26 | |
27 | struct TriviallyCopyable { |
28 | explicit TriviallyCopyable(int i) : i_(i) { } |
29 | int i_; |
30 | }; |
31 | |
32 | template <class T> |
33 | void test(T t) { |
34 | std::atomic<T> t0(t); |
35 | } |
36 | |
37 | int main(int, char**) { |
38 | test(t: TriviallyCopyable(42)); |
39 | test(t: std::chrono::nanoseconds(2)); |
40 | #ifndef TEST_HAS_NO_THREADS |
41 | test(t: std::this_thread::get_id()); |
42 | #endif |
43 | |
44 | return 0; |
45 | } |
46 | |