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 // template <class T, class... Args> 13 // struct is_nothrow_constructible; 14 15 #include <type_traits> 16 #include "test_macros.h" 17 18 template <class T> 19 void test_is_nothrow_constructible() 20 { 21 static_assert(( std::is_nothrow_constructible<T>::value), ""); 22 #if TEST_STD_VER > 14 23 static_assert(( std::is_nothrow_constructible_v<T>), ""); 24 #endif 25 } 26 27 template <class T, class A0> 28 void test_is_nothrow_constructible() 29 { 30 static_assert(( std::is_nothrow_constructible<T, A0>::value), ""); 31 #if TEST_STD_VER > 14 32 static_assert(( std::is_nothrow_constructible_v<T, A0>), ""); 33 #endif 34 } 35 36 template <class T> 37 void test_is_not_nothrow_constructible() 38 { 39 static_assert((!std::is_nothrow_constructible<T>::value), ""); 40 #if TEST_STD_VER > 14 41 static_assert((!std::is_nothrow_constructible_v<T>), ""); 42 #endif 43 } 44 45 template <class T, class A0> 46 void test_is_not_nothrow_constructible() 47 { 48 static_assert((!std::is_nothrow_constructible<T, A0>::value), ""); 49 #if TEST_STD_VER > 14 50 static_assert((!std::is_nothrow_constructible_v<T, A0>), ""); 51 #endif 52 } 53 54 template <class T, class A0, class A1> 55 void test_is_not_nothrow_constructible() 56 { 57 static_assert((!std::is_nothrow_constructible<T, A0, A1>::value), ""); 58 #if TEST_STD_VER > 14 59 static_assert((!std::is_nothrow_constructible_v<T, A0, A1>), ""); 60 #endif 61 } 62 63 class Empty 64 { 65 }; 66 67 class NotEmpty 68 { 69 virtual ~NotEmpty(); 70 }; 71 72 union Union {}; 73 74 struct bit_zero 75 { 76 int : 0; 77 }; 78 79 class Abstract 80 { 81 virtual ~Abstract() = 0; 82 }; 83 84 struct A 85 { 86 A(const A&); 87 }; 88 89 struct C 90 { 91 C(C&); // not const 92 void operator=(C&); // not const 93 }; 94 95 #if TEST_STD_VER >= 11 96 struct Tuple { 97 Tuple(Empty&&) noexcept {} 98 }; 99 #endif 100 101 int main() 102 { 103 test_is_nothrow_constructible<int> (); 104 test_is_nothrow_constructible<int, const int&> (); 105 test_is_nothrow_constructible<Empty> (); 106 test_is_nothrow_constructible<Empty, const Empty&> (); 107 108 test_is_not_nothrow_constructible<A, int> (); 109 test_is_not_nothrow_constructible<A, int, double> (); 110 test_is_not_nothrow_constructible<A> (); 111 test_is_not_nothrow_constructible<C> (); 112 #if TEST_STD_VER >= 11 113 test_is_nothrow_constructible<Tuple &&, Empty> (); // See bug #19616. 114 115 static_assert(!std::is_constructible<Tuple&, Empty>::value, ""); 116 test_is_not_nothrow_constructible<Tuple &, Empty> (); // See bug #19616. 117 #endif 118 } 119