1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // type_traits
11
12 // is_trivially_copyable
13
14 // These compilers have not implemented Core 2094 which makes volatile
15 // qualified types trivially copyable.
16 // XFAIL: clang-3, clang-4, apple-clang, gcc
17
18 #include <type_traits>
19 #include <cassert>
20 #include "test_macros.h"
21
22 template <class T>
test_is_trivially_copyable()23 void test_is_trivially_copyable()
24 {
25 static_assert( std::is_trivially_copyable<T>::value, "");
26 static_assert( std::is_trivially_copyable<const T>::value, "");
27 static_assert( std::is_trivially_copyable<volatile T>::value, "");
28 static_assert( std::is_trivially_copyable<const volatile T>::value, "");
29 #if TEST_STD_VER > 14
30 static_assert( std::is_trivially_copyable_v<T>, "");
31 static_assert( std::is_trivially_copyable_v<const T>, "");
32 static_assert( std::is_trivially_copyable_v<volatile T>, "");
33 static_assert( std::is_trivially_copyable_v<const volatile T>, "");
34 #endif
35 }
36
37 template <class T>
test_is_not_trivially_copyable()38 void test_is_not_trivially_copyable()
39 {
40 static_assert(!std::is_trivially_copyable<T>::value, "");
41 static_assert(!std::is_trivially_copyable<const T>::value, "");
42 static_assert(!std::is_trivially_copyable<volatile T>::value, "");
43 static_assert(!std::is_trivially_copyable<const volatile T>::value, "");
44 #if TEST_STD_VER > 14
45 static_assert(!std::is_trivially_copyable_v<T>, "");
46 static_assert(!std::is_trivially_copyable_v<const T>, "");
47 static_assert(!std::is_trivially_copyable_v<volatile T>, "");
48 static_assert(!std::is_trivially_copyable_v<const volatile T>, "");
49 #endif
50 }
51
52 struct A
53 {
54 int i_;
55 };
56
57 struct B
58 {
59 int i_;
~BB60 ~B() {assert(i_ == 0);}
61 };
62
63 class C
64 {
65 public:
66 C();
67 };
68
main()69 int main()
70 {
71 test_is_trivially_copyable<int> ();
72 test_is_trivially_copyable<const int> ();
73 test_is_trivially_copyable<A> ();
74 test_is_trivially_copyable<const A> ();
75 test_is_trivially_copyable<C> ();
76
77 test_is_not_trivially_copyable<int&> ();
78 test_is_not_trivially_copyable<const A&> ();
79 test_is_not_trivially_copyable<B> ();
80 }
81