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_copyable
12
13 #include <type_traits>
14 #include <cassert>
15 #include "test_macros.h"
16
17 template <class T>
test_is_trivially_copyable()18 void test_is_trivially_copyable()
19 {
20 static_assert( std::is_trivially_copyable<T>::value, "");
21 static_assert( std::is_trivially_copyable<const T>::value, "");
22 static_assert( std::is_trivially_copyable<volatile T>::value, "");
23 static_assert( std::is_trivially_copyable<const volatile T>::value, "");
24 #if TEST_STD_VER > 14
25 static_assert( std::is_trivially_copyable_v<T>, "");
26 static_assert( std::is_trivially_copyable_v<const T>, "");
27 static_assert( std::is_trivially_copyable_v<volatile T>, "");
28 static_assert( std::is_trivially_copyable_v<const volatile T>, "");
29 #endif
30 }
31
32 template <class T>
test_is_not_trivially_copyable()33 void test_is_not_trivially_copyable()
34 {
35 static_assert(!std::is_trivially_copyable<T>::value, "");
36 static_assert(!std::is_trivially_copyable<const T>::value, "");
37 static_assert(!std::is_trivially_copyable<volatile T>::value, "");
38 static_assert(!std::is_trivially_copyable<const volatile T>::value, "");
39 #if TEST_STD_VER > 14
40 static_assert(!std::is_trivially_copyable_v<T>, "");
41 static_assert(!std::is_trivially_copyable_v<const T>, "");
42 static_assert(!std::is_trivially_copyable_v<volatile T>, "");
43 static_assert(!std::is_trivially_copyable_v<const volatile T>, "");
44 #endif
45 }
46
47 struct A
48 {
49 int i_;
50 };
51
52 struct B
53 {
54 int i_;
~BB55 ~B() {assert(i_ == 0);}
56 };
57
58 class C
59 {
60 public:
61 C();
62 };
63
main(int,char **)64 int main(int, char**)
65 {
66 test_is_trivially_copyable<int> ();
67 test_is_trivially_copyable<const int> ();
68 test_is_trivially_copyable<A> ();
69 test_is_trivially_copyable<const A> ();
70 test_is_trivially_copyable<C> ();
71
72 test_is_not_trivially_copyable<int&> ();
73 test_is_not_trivially_copyable<const A&> ();
74 test_is_not_trivially_copyable<B> ();
75
76 return 0;
77 }
78