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