• 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_copy_constructible
13 
14 #include <type_traits>
15 #include "test_macros.h"
16 
17 template <class T>
test_is_copy_constructible()18 void test_is_copy_constructible()
19 {
20     static_assert( std::is_copy_constructible<T>::value, "");
21 #if TEST_STD_VER > 14
22     static_assert( std::is_copy_constructible_v<T>, "");
23 #endif
24 }
25 
26 template <class T>
test_is_not_copy_constructible()27 void test_is_not_copy_constructible()
28 {
29     static_assert(!std::is_copy_constructible<T>::value, "");
30 #if TEST_STD_VER > 14
31     static_assert(!std::is_copy_constructible_v<T>, "");
32 #endif
33 }
34 
35 class Empty
36 {
37 };
38 
39 class NotEmpty
40 {
41 public:
42     virtual ~NotEmpty();
43 };
44 
45 union Union {};
46 
47 struct bit_zero
48 {
49     int :  0;
50 };
51 
52 class Abstract
53 {
54 public:
55     virtual ~Abstract() = 0;
56 };
57 
58 struct A
59 {
60     A(const A&);
61 };
62 
63 class B
64 {
65     B(const B&);
66 };
67 
68 struct C
69 {
70     C(C&);  // not const
71     void operator=(C&);  // not const
72 };
73 
main()74 int main()
75 {
76     test_is_copy_constructible<A>();
77     test_is_copy_constructible<int&>();
78     test_is_copy_constructible<Union>();
79     test_is_copy_constructible<Empty>();
80     test_is_copy_constructible<int>();
81     test_is_copy_constructible<double>();
82     test_is_copy_constructible<int*>();
83     test_is_copy_constructible<const int*>();
84     test_is_copy_constructible<NotEmpty>();
85     test_is_copy_constructible<bit_zero>();
86 
87     test_is_not_copy_constructible<char[3]>();
88     test_is_not_copy_constructible<char[]>();
89     test_is_not_copy_constructible<void>();
90     test_is_not_copy_constructible<Abstract>();
91     test_is_not_copy_constructible<C>();
92 #if TEST_STD_VER >= 11
93     test_is_not_copy_constructible<B>();
94 #endif
95 }
96