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()17void 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()26void 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 NoDefaultConstructor 39 { NoDefaultConstructor(int)40 NoDefaultConstructor(int) {} 41 }; 42 43 class NotEmpty 44 { 45 public: 46 virtual ~NotEmpty(); 47 }; 48 49 union Union {}; 50 51 struct bit_zero 52 { 53 int : 0; 54 }; 55 56 class Abstract 57 { 58 public: 59 virtual ~Abstract() = 0; 60 }; 61 62 struct A 63 { 64 A(); 65 }; 66 67 class B 68 { 69 B(); 70 }; 71 main()72int main() 73 { 74 test_is_default_constructible<A>(); 75 test_is_default_constructible<Union>(); 76 test_is_default_constructible<Empty>(); 77 test_is_default_constructible<int>(); 78 test_is_default_constructible<double>(); 79 test_is_default_constructible<int*>(); 80 test_is_default_constructible<const int*>(); 81 test_is_default_constructible<char[3]>(); 82 test_is_default_constructible<NotEmpty>(); 83 test_is_default_constructible<bit_zero>(); 84 85 test_is_not_default_constructible<void>(); 86 test_is_not_default_constructible<int&>(); 87 test_is_not_default_constructible<char[]>(); 88 test_is_not_default_constructible<Abstract>(); 89 test_is_not_default_constructible<NoDefaultConstructor>(); 90 #if __has_feature(cxx_access_control_sfinae) 91 test_is_not_default_constructible<B>(); 92 #endif 93 } 94