has_trivial_destructor_test.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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_destructor.hpp>
  9. #endif
  10. #include "test.hpp"
  11. #include "check_integral_constant.hpp"
  12. #ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
  13. struct deleted_destruct
  14. {
  15. deleted_destruct();
  16. ~deleted_destruct() = delete;
  17. };
  18. #endif
  19. struct private_destruct
  20. {
  21. private_destruct();
  22. private:
  23. ~private_destruct();
  24. };
  25. TT_TEST_BEGIN(has_trivial_destructor)
  26. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<bool>::value, true);
  27. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<bool const>::value, true);
  28. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<bool volatile>::value, true);
  29. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<bool const volatile>::value, true);
  30. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<signed char>::value, true);
  31. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<signed char const>::value, true);
  32. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<signed char volatile>::value, true);
  33. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<signed char const volatile>::value, true);
  34. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned char>::value, true);
  35. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<char>::value, true);
  36. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned char const>::value, true);
  37. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<char const>::value, true);
  38. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned char volatile>::value, true);
  39. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<char volatile>::value, true);
  40. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned char const volatile>::value, true);
  41. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<char const volatile>::value, true);
  42. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned short>::value, true);
  43. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<short>::value, true);
  44. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned short const>::value, true);
  45. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<short const>::value, true);
  46. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned short volatile>::value, true);
  47. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<short volatile>::value, true);
  48. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned short const volatile>::value, true);
  49. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<short const volatile>::value, true);
  50. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned int>::value, true);
  51. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int>::value, true);
  52. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned int const>::value, true);
  53. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int const>::value, true);
  54. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned int volatile>::value, true);
  55. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int volatile>::value, true);
  56. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned int const volatile>::value, true);
  57. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int const volatile>::value, true);
  58. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned long>::value, true);
  59. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<long>::value, true);
  60. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned long const>::value, true);
  61. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<long const>::value, true);
  62. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned long volatile>::value, true);
  63. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<long volatile>::value, true);
  64. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned long const volatile>::value, true);
  65. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<long const volatile>::value, true);
  66. #ifdef BOOST_HAS_LONG_LONG
  67. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor< ::boost::ulong_long_type>::value, true);
  68. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor< ::boost::long_long_type>::value, true);
  69. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor< ::boost::ulong_long_type const>::value, true);
  70. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor< ::boost::long_long_type const>::value, true);
  71. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor< ::boost::ulong_long_type volatile>::value, true);
  72. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor< ::boost::long_long_type volatile>::value, true);
  73. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor< ::boost::ulong_long_type const volatile>::value, true);
  74. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor< ::boost::long_long_type const volatile>::value, true);
  75. #endif
  76. #ifdef BOOST_HAS_MS_INT64
  77. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int8>::value, true);
  78. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int8>::value, true);
  79. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int8 const>::value, true);
  80. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int8 const>::value, true);
  81. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int8 volatile>::value, true);
  82. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int8 volatile>::value, true);
  83. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int8 const volatile>::value, true);
  84. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int8 const volatile>::value, true);
  85. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int16>::value, true);
  86. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int16>::value, true);
  87. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int16 const>::value, true);
  88. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int16 const>::value, true);
  89. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int16 volatile>::value, true);
  90. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int16 volatile>::value, true);
  91. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int16 const volatile>::value, true);
  92. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int16 const volatile>::value, true);
  93. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int32>::value, true);
  94. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int32>::value, true);
  95. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int32 const>::value, true);
  96. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int32 const>::value, true);
  97. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int32 volatile>::value, true);
  98. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int32 volatile>::value, true);
  99. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int32 const volatile>::value, true);
  100. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int32 const volatile>::value, true);
  101. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int64>::value, true);
  102. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int64>::value, true);
  103. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int64 const>::value, true);
  104. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int64 const>::value, true);
  105. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int64 volatile>::value, true);
  106. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int64 volatile>::value, true);
  107. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<unsigned __int64 const volatile>::value, true);
  108. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<__int64 const volatile>::value, true);
  109. #endif
  110. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<float>::value, true);
  111. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<float const>::value, true);
  112. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<float volatile>::value, true);
  113. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<float const volatile>::value, true);
  114. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<double>::value, true);
  115. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<double const>::value, true);
  116. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<double volatile>::value, true);
  117. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<double const volatile>::value, true);
  118. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<long double>::value, true);
  119. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<long double const>::value, true);
  120. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<long double volatile>::value, true);
  121. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<long double const volatile>::value, true);
  122. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int>::value, true);
  123. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<void*>::value, true);
  124. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int*const>::value, true);
  125. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<f1>::value, true);
  126. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<f2>::value, true);
  127. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<f3>::value, true);
  128. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<mf1>::value, true);
  129. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<mf2>::value, true);
  130. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<mf3>::value, true);
  131. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<mp>::value, true);
  132. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<cmf>::value, true);
  133. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<enum_UDT>::value, true);
  134. //
  135. // These are commented out for now because it's not clear what the semantics should be:
  136. // on the one hand references always have trivial destructors (in the sense that there is
  137. // nothing to destruct), on the other hand the thing referenced may not have a trivial
  138. // destructor, it really depends upon the users code as to what should happen here:
  139. //
  140. //BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int&>::value, false);
  141. //BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<const int&>::value, false);
  142. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int[2]>::value, true);
  143. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int[3][2]>::value, true);
  144. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<int[2][4][5][6][3]>::value, true);
  145. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<UDT>::value, false);
  146. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<empty_UDT>::value, false);
  147. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<void>::value, false);
  148. // cases we would like to succeed but can't implement in the language:
  149. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<empty_POD_UDT>::value, true, false);
  150. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<POD_UDT>::value, true, false);
  151. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<POD_union_UDT>::value, true, false);
  152. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<empty_POD_union_UDT>::value, true, false);
  153. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<trivial_except_destroy>::value, false);
  154. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<trivial_except_copy>::value, true, false);
  155. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<trivial_except_construct>::value, true, false);
  156. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<trivial_except_assign>::value, true, false);
  157. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<wrap<trivial_except_destroy> >::value, false);
  158. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<wrap<trivial_except_copy> >::value, true, false);
  159. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<wrap<trivial_except_construct> >::value, true, false);
  160. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<wrap<trivial_except_assign> >::value, true, false);
  161. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<private_destruct>::value, false);
  162. #ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
  163. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<deleted_destruct>::value, false);
  164. #endif
  165. TT_TEST_END