has_nothrow_assign_test.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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_nothrow_assign.hpp>
  9. #endif
  10. #include "test.hpp"
  11. #include "check_integral_constant.hpp"
  12. #ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
  13. struct non_assignable
  14. {
  15. non_assignable();
  16. non_assignable& operator=(const non_assignable&) = delete;
  17. };
  18. #endif
  19. #ifndef BOOST_NO_CXX11_NOEXCEPT
  20. struct noexcept_assignable
  21. {
  22. noexcept_assignable();
  23. noexcept_assignable& operator=(const noexcept_assignable&)noexcept;
  24. };
  25. #endif
  26. TT_TEST_BEGIN(has_nothrow_assign)
  27. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<bool>::value, true);
  28. #ifndef TEST_STD
  29. // unspecified behaviour:
  30. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<bool const>::value, false);
  31. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<bool volatile>::value, false);
  32. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<bool const volatile>::value, false);
  33. #endif
  34. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<signed char>::value, true);
  35. #ifndef TEST_STD
  36. // unspecified behaviour:
  37. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<signed char const>::value, false);
  38. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<signed char volatile>::value, false);
  39. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<signed char const volatile>::value, false);
  40. #endif
  41. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned char>::value, true);
  42. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<char>::value, true);
  43. #ifndef TEST_STD
  44. // unspecified behaviour:
  45. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned char const>::value, false);
  46. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<char const>::value, false);
  47. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned char volatile>::value, false);
  48. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<char volatile>::value, false);
  49. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned char const volatile>::value, false);
  50. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<char const volatile>::value, false);
  51. #endif
  52. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned short>::value, true);
  53. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<short>::value, true);
  54. #ifndef TEST_STD
  55. // unspecified behaviour:
  56. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned short const>::value, false);
  57. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<short const>::value, false);
  58. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned short volatile>::value, false);
  59. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<short volatile>::value, false);
  60. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned short const volatile>::value, false);
  61. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<short const volatile>::value, false);
  62. #endif
  63. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned int>::value, true);
  64. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int>::value, true);
  65. #ifndef TEST_STD
  66. // unspecified behaviour:
  67. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned int const>::value, false);
  68. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int const>::value, false);
  69. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned int volatile>::value, false);
  70. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int volatile>::value, false);
  71. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned int const volatile>::value, false);
  72. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int const volatile>::value, false);
  73. #endif
  74. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned long>::value, true);
  75. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<long>::value, true);
  76. #ifndef TEST_STD
  77. // unspecified behaviour:
  78. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned long const>::value, false);
  79. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<long const>::value, false);
  80. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned long volatile>::value, false);
  81. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<long volatile>::value, false);
  82. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned long const volatile>::value, false);
  83. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<long const volatile>::value, false);
  84. #endif
  85. #ifdef BOOST_HAS_LONG_LONG
  86. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign< ::boost::ulong_long_type>::value, true);
  87. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign< ::boost::long_long_type>::value, true);
  88. #ifndef TEST_STD
  89. // unspecified behaviour:
  90. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign< ::boost::ulong_long_type const>::value, false);
  91. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign< ::boost::long_long_type const>::value, false);
  92. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign< ::boost::ulong_long_type volatile>::value, false);
  93. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign< ::boost::long_long_type volatile>::value, false);
  94. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign< ::boost::ulong_long_type const volatile>::value, false);
  95. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign< ::boost::long_long_type const volatile>::value, false);
  96. #endif
  97. #endif
  98. #ifdef BOOST_HAS_MS_INT64
  99. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int8>::value, true);
  100. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int8>::value, true);
  101. #ifndef TEST_STD
  102. // unspecified behaviour:
  103. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int8 const>::value, false);
  104. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int8 const>::value, false);
  105. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int8 volatile>::value, false);
  106. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int8 volatile>::value, false);
  107. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int8 const volatile>::value, false);
  108. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int8 const volatile>::value, false);
  109. #endif
  110. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int16>::value, true);
  111. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int16>::value, true);
  112. #ifndef TEST_STD
  113. // unspecified behaviour:
  114. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int16 const>::value, false);
  115. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int16 const>::value, false);
  116. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int16 volatile>::value, false);
  117. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int16 volatile>::value, false);
  118. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int16 const volatile>::value, false);
  119. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int16 const volatile>::value, false);
  120. #endif
  121. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int32>::value, true);
  122. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int32>::value, true);
  123. #ifndef TEST_STD
  124. // unspecified behaviour:
  125. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int32 const>::value, false);
  126. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int32 const>::value, false);
  127. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int32 volatile>::value, false);
  128. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int32 volatile>::value, false);
  129. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int32 const volatile>::value, false);
  130. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int32 const volatile>::value, false);
  131. #endif
  132. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int64>::value, true);
  133. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int64>::value, true);
  134. #ifndef TEST_STD
  135. // unspecified behaviour:
  136. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int64 const>::value, false);
  137. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int64 const>::value, false);
  138. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int64 volatile>::value, false);
  139. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int64 volatile>::value, false);
  140. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<unsigned __int64 const volatile>::value, false);
  141. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<__int64 const volatile>::value, false);
  142. #endif
  143. #endif
  144. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<float>::value, true);
  145. #ifndef TEST_STD
  146. // unspecified behaviour:
  147. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<float const>::value, false);
  148. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<float volatile>::value, false);
  149. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<float const volatile>::value, false);
  150. #endif
  151. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<double>::value, true);
  152. #ifndef TEST_STD
  153. // unspecified behaviour:
  154. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<double const>::value, false);
  155. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<double volatile>::value, false);
  156. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<double const volatile>::value, false);
  157. #endif
  158. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<long double>::value, true);
  159. #ifndef TEST_STD
  160. // unspecified behaviour:
  161. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<long double const>::value, false);
  162. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<long double volatile>::value, false);
  163. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<long double const volatile>::value, false);
  164. #endif
  165. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int>::value, true);
  166. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<void*>::value, true);
  167. #ifndef TEST_STD
  168. // unspecified behaviour:
  169. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int*const>::value, false);
  170. #endif
  171. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<f1>::value, true);
  172. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<f2>::value, true);
  173. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<f3>::value, true);
  174. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<mf1>::value, true);
  175. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<mf2>::value, true);
  176. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<mf3>::value, true);
  177. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<mp>::value, true);
  178. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<cmf>::value, true);
  179. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<enum_UDT>::value, true);
  180. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int&>::value, false);
  181. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  182. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int&&>::value, false);
  183. #endif
  184. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<const int&>::value, false);
  185. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int[2]>::value, true);
  186. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int[3][2]>::value, true);
  187. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<int[2][4][5][6][3]>::value, true);
  188. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<UDT>::value, false);
  189. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<empty_UDT>::value, false);
  190. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<void>::value, false);
  191. // cases we would like to succeed but can't implement in the language:
  192. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<empty_POD_UDT>::value, true, false);
  193. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<POD_UDT>::value, true, false);
  194. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<POD_union_UDT>::value, true, false);
  195. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<empty_POD_union_UDT>::value, true, false);
  196. BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<nothrow_assign_UDT>::value, true, false);
  197. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<nothrow_copy_UDT>::value, false);
  198. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<nothrow_construct_UDT>::value, false);
  199. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<test_abc1>::value, false);
  200. #ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
  201. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<non_assignable>::value, false);
  202. #endif
  203. #ifndef BOOST_NO_CXX11_NOEXCEPT
  204. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_assign<noexcept_assignable>::value, true);
  205. #endif
  206. TT_TEST_END