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 // These compilers have not implemented Core 2094 which makes volatile
14 // qualified types trivially copyable.
15 // XFAIL: clang-4, apple-clang-9.0, gcc
16 
17 #include <type_traits>
18 #include <cassert>
19 #include "test_macros.h"
20 
21 template <class T>
test_is_trivially_copyable()22 void test_is_trivially_copyable()
23 {
24     static_assert( std::is_trivially_copyable<T>::value, "");
25     static_assert( std::is_trivially_copyable<const T>::value, "");
26     static_assert( std::is_trivially_copyable<volatile T>::value, "");
27     static_assert( std::is_trivially_copyable<const volatile T>::value, "");
28 #if TEST_STD_VER > 14
29     static_assert( std::is_trivially_copyable_v<T>, "");
30     static_assert( std::is_trivially_copyable_v<const T>, "");
31     static_assert( std::is_trivially_copyable_v<volatile T>, "");
32     static_assert( std::is_trivially_copyable_v<const volatile T>, "");
33 #endif
34 }
35 
36 template <class T>
test_is_not_trivially_copyable()37 void test_is_not_trivially_copyable()
38 {
39     static_assert(!std::is_trivially_copyable<T>::value, "");
40     static_assert(!std::is_trivially_copyable<const T>::value, "");
41     static_assert(!std::is_trivially_copyable<volatile T>::value, "");
42     static_assert(!std::is_trivially_copyable<const volatile T>::value, "");
43 #if TEST_STD_VER > 14
44     static_assert(!std::is_trivially_copyable_v<T>, "");
45     static_assert(!std::is_trivially_copyable_v<const T>, "");
46     static_assert(!std::is_trivially_copyable_v<volatile T>, "");
47     static_assert(!std::is_trivially_copyable_v<const volatile T>, "");
48 #endif
49 }
50 
51 struct A
52 {
53     int i_;
54 };
55 
56 struct B
57 {
58     int i_;
~BB59     ~B() {assert(i_ == 0);}
60 };
61 
62 class C
63 {
64 public:
65     C();
66 };
67 
main(int,char **)68 int main(int, char**)
69 {
70     test_is_trivially_copyable<int> ();
71     test_is_trivially_copyable<const int> ();
72     test_is_trivially_copyable<A> ();
73     test_is_trivially_copyable<const A> ();
74     test_is_trivially_copyable<C> ();
75 
76     test_is_not_trivially_copyable<int&> ();
77     test_is_not_trivially_copyable<const A&> ();
78     test_is_not_trivially_copyable<B> ();
79 
80   return 0;
81 }
82