1 2 // (C) Copyright John Maddock 2000. 3 // Use, modification and distribution are subject to the 4 // Boost Software License, Version 1.0. (See accompanying file 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 #include "test.hpp" 8 #include "check_integral_constant.hpp" 9 #ifdef TEST_STD 10 # include <type_traits> 11 #else 12 # include <boost/type_traits/has_nothrow_constructor.hpp> 13 #endif 14 15 class bug11324_base 16 { 17 public: operator =(const bug11324_base &)18 bug11324_base & operator=(const bug11324_base&){ throw int(); } ~bug11324_base()19 virtual ~bug11324_base() {} 20 }; 21 22 class bug11324_derived : public bug11324_base 23 { 24 public: 25 char data; bug11324_derived(char arg)26 explicit bug11324_derived(char arg) : data(arg) {} 27 }; 28 29 30 TT_TEST_BEGIN(has_nothrow_constructor) 31 32 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<bool>::value, true); 33 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<bool const>::value, true); 34 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<bool volatile>::value, true); 35 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<bool const volatile>::value, true); 36 37 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<signed char>::value, true); 38 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<signed char const>::value, true); 39 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<signed char volatile>::value, true); 40 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<signed char const volatile>::value, true); 41 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned char>::value, true); 42 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<char>::value, true); 43 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned char const>::value, true); 44 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<char const>::value, true); 45 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned char volatile>::value, true); 46 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<char volatile>::value, true); 47 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned char const volatile>::value, true); 48 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<char const volatile>::value, true); 49 50 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned short>::value, true); 51 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<short>::value, true); 52 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned short const>::value, true); 53 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<short const>::value, true); 54 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned short volatile>::value, true); 55 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<short volatile>::value, true); 56 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned short const volatile>::value, true); 57 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<short const volatile>::value, true); 58 59 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned int>::value, true); 60 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int>::value, true); 61 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned int const>::value, true); 62 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int const>::value, true); 63 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned int volatile>::value, true); 64 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int volatile>::value, true); 65 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned int const volatile>::value, true); 66 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int const volatile>::value, true); 67 68 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned long>::value, true); 69 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<long>::value, true); 70 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned long const>::value, true); 71 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<long const>::value, true); 72 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned long volatile>::value, true); 73 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<long volatile>::value, true); 74 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned long const volatile>::value, true); 75 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<long const volatile>::value, true); 76 77 #ifdef BOOST_HAS_LONG_LONG 78 79 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor< ::boost::ulong_long_type>::value, true); 80 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor< ::boost::long_long_type>::value, true); 81 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor< ::boost::ulong_long_type const>::value, true); 82 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor< ::boost::long_long_type const>::value, true); 83 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor< ::boost::ulong_long_type volatile>::value, true); 84 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor< ::boost::long_long_type volatile>::value, true); 85 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor< ::boost::ulong_long_type const volatile>::value, true); 86 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor< ::boost::long_long_type const volatile>::value, true); 87 88 #endif 89 90 #ifdef BOOST_HAS_MS_INT64 91 92 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int8>::value, true); 93 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int8>::value, true); 94 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int8 const>::value, true); 95 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int8 const>::value, true); 96 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int8 volatile>::value, true); 97 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int8 volatile>::value, true); 98 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int8 const volatile>::value, true); 99 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int8 const volatile>::value, true); 100 101 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int16>::value, true); 102 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int16>::value, true); 103 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int16 const>::value, true); 104 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int16 const>::value, true); 105 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int16 volatile>::value, true); 106 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int16 volatile>::value, true); 107 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int16 const volatile>::value, true); 108 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int16 const volatile>::value, true); 109 110 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int32>::value, true); 111 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int32>::value, true); 112 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int32 const>::value, true); 113 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int32 const>::value, true); 114 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int32 volatile>::value, true); 115 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int32 volatile>::value, true); 116 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int32 const volatile>::value, true); 117 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int32 const volatile>::value, true); 118 119 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int64>::value, true); 120 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int64>::value, true); 121 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int64 const>::value, true); 122 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int64 const>::value, true); 123 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int64 volatile>::value, true); 124 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int64 volatile>::value, true); 125 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<unsigned __int64 const volatile>::value, true); 126 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<__int64 const volatile>::value, true); 127 128 #endif 129 130 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<float>::value, true); 131 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<float const>::value, true); 132 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<float volatile>::value, true); 133 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<float const volatile>::value, true); 134 135 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<double>::value, true); 136 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<double const>::value, true); 137 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<double volatile>::value, true); 138 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<double const volatile>::value, true); 139 140 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<long double>::value, true); 141 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<long double const>::value, true); 142 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<long double volatile>::value, true); 143 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<long double const volatile>::value, true); 144 145 146 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int>::value, true); 147 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<void*>::value, true); 148 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int*const>::value, true); 149 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<f1>::value, true); 150 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<f2>::value, true); 151 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<f3>::value, true); 152 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<mf1>::value, true); 153 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<mf2>::value, true); 154 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<mf3>::value, true); 155 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<mp>::value, true); 156 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<cmf>::value, true); 157 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<enum_UDT>::value, true); 158 159 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int&>::value, false); 160 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 161 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int&&>::value, false); 162 #endif 163 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<const int&>::value, false); 164 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int[2]>::value, true); 165 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int[3][2]>::value, true); 166 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<int[2][4][5][6][3]>::value, true); 167 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<UDT>::value, false); 168 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<empty_UDT>::value, false); 169 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<void>::value, false); 170 // cases we would like to succeed but can't implement in the language: 171 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<empty_POD_UDT>::value, true, false); 172 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<POD_UDT>::value, true, false); 173 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<POD_union_UDT>::value, true, false); 174 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<empty_POD_union_UDT>::value, true, false); 175 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<nothrow_construct_UDT>::value, true, false); 176 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<nothrow_assign_UDT>::value, false); 177 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<nothrow_copy_UDT>::value, false); 178 179 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<test_abc1>::value, false); 180 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<bug11324_derived>::value, false); 181 182 TT_TEST_END 183 184 185 186