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 | // type_traits |
10 | |
11 | // is_trivially_copy_constructible |
12 | |
13 | #include <type_traits> |
14 | #include "test_macros.h" |
15 | |
16 | template <class T> |
17 | void test_is_trivially_copy_constructible() |
18 | { |
19 | static_assert( std::is_trivially_copy_constructible<T>::value, "" ); |
20 | static_assert( std::is_trivially_copy_constructible<const T>::value, "" ); |
21 | #if TEST_STD_VER > 14 |
22 | static_assert( std::is_trivially_copy_constructible_v<T>, "" ); |
23 | static_assert( std::is_trivially_copy_constructible_v<const T>, "" ); |
24 | #endif |
25 | } |
26 | |
27 | template <class T> |
28 | void test_has_not_trivial_copy_constructor() |
29 | { |
30 | static_assert(!std::is_trivially_copy_constructible<T>::value, "" ); |
31 | static_assert(!std::is_trivially_copy_constructible<const T>::value, "" ); |
32 | #if TEST_STD_VER > 14 |
33 | static_assert(!std::is_trivially_copy_constructible_v<T>, "" ); |
34 | static_assert(!std::is_trivially_copy_constructible_v<const T>, "" ); |
35 | #endif |
36 | } |
37 | |
38 | class Empty |
39 | { |
40 | }; |
41 | |
42 | class NotEmpty |
43 | { |
44 | public: |
45 | virtual ~NotEmpty(); |
46 | }; |
47 | |
48 | union Union {}; |
49 | |
50 | struct bit_zero |
51 | { |
52 | int : 0; |
53 | }; |
54 | |
55 | class Abstract |
56 | { |
57 | public: |
58 | virtual ~Abstract() = 0; |
59 | }; |
60 | |
61 | struct A |
62 | { |
63 | A(const A&); |
64 | }; |
65 | |
66 | int main(int, char**) |
67 | { |
68 | test_has_not_trivial_copy_constructor<void>(); |
69 | test_has_not_trivial_copy_constructor<A>(); |
70 | test_has_not_trivial_copy_constructor<Abstract>(); |
71 | test_has_not_trivial_copy_constructor<NotEmpty>(); |
72 | |
73 | test_is_trivially_copy_constructible<int&>(); |
74 | test_is_trivially_copy_constructible<Union>(); |
75 | test_is_trivially_copy_constructible<Empty>(); |
76 | test_is_trivially_copy_constructible<int>(); |
77 | test_is_trivially_copy_constructible<double>(); |
78 | test_is_trivially_copy_constructible<int*>(); |
79 | test_is_trivially_copy_constructible<const int*>(); |
80 | test_is_trivially_copy_constructible<bit_zero>(); |
81 | |
82 | return 0; |
83 | } |
84 | |