has_trivial_constr_test.cpp 13 KB

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