• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <type_traits>
15 #include <cassert>
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 }
25 
26 template <class T>
test_is_not_trivially_copyable()27 void test_is_not_trivially_copyable()
28 {
29     static_assert(!std::is_trivially_copyable<T>::value, "");
30     static_assert(!std::is_trivially_copyable<const T>::value, "");
31     static_assert(!std::is_trivially_copyable<volatile T>::value, "");
32     static_assert(!std::is_trivially_copyable<const volatile T>::value, "");
33 }
34 
35 struct A
36 {
37     int i_;
38 };
39 
40 struct B
41 {
42     int i_;
~BB43     ~B() {assert(i_ == 0);}
44 };
45 
46 class C
47 {
48 public:
49     C();
50 };
51 
main()52 int main()
53 {
54     test_is_trivially_copyable<int> ();
55     test_is_trivially_copyable<const int> ();
56     test_is_trivially_copyable<A> ();
57     test_is_trivially_copyable<const A> ();
58     test_is_trivially_copyable<C> ();
59 
60     test_is_not_trivially_copyable<int&> ();
61     test_is_not_trivially_copyable<const A&> ();
62     test_is_not_trivially_copyable<B> ();
63 }
64