workaround.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost
  4. // 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. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_MOVE_DETAIL_WORKAROUND_HPP
  11. #define BOOST_MOVE_DETAIL_WORKAROUND_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #
  16. #if defined(BOOST_HAS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif
  19. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  20. #define BOOST_MOVE_PERFECT_FORWARDING
  21. #endif
  22. #if defined(__has_feature)
  23. #define BOOST_MOVE_HAS_FEATURE __has_feature
  24. #else
  25. #define BOOST_MOVE_HAS_FEATURE(x) 0
  26. #endif
  27. #if BOOST_MOVE_HAS_FEATURE(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
  28. #define BOOST_MOVE_ADDRESS_SANITIZER_ON
  29. #endif
  30. //Macros for documentation purposes. For code, expands to the argument
  31. #define BOOST_MOVE_IMPDEF(TYPE) TYPE
  32. #define BOOST_MOVE_SEEDOC(TYPE) TYPE
  33. #define BOOST_MOVE_DOC0PTR(TYPE) TYPE
  34. #define BOOST_MOVE_DOC1ST(TYPE1, TYPE2) TYPE2
  35. #define BOOST_MOVE_I ,
  36. #define BOOST_MOVE_DOCIGN(T1) T1
  37. #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 5) && !defined(__clang__)
  38. //Pre-standard rvalue binding rules
  39. #define BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
  40. #elif defined(_MSC_VER) && (_MSC_VER == 1600)
  41. //Standard rvalue binding rules but with some bugs
  42. #define BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG
  43. #define BOOST_MOVE_MSVC_AUTO_MOVE_RETURN_BUG
  44. #elif defined(_MSC_VER) && (_MSC_VER == 1700)
  45. #define BOOST_MOVE_MSVC_AUTO_MOVE_RETURN_BUG
  46. #endif
  47. //#define BOOST_MOVE_DISABLE_FORCEINLINE
  48. #if defined(BOOST_MOVE_DISABLE_FORCEINLINE)
  49. #define BOOST_MOVE_FORCEINLINE inline
  50. #elif defined(BOOST_MOVE_FORCEINLINE_IS_BOOST_FORCELINE)
  51. #define BOOST_MOVE_FORCEINLINE BOOST_FORCEINLINE
  52. #elif defined(BOOST_MSVC) && (_MSC_VER < 1900 || defined(_DEBUG))
  53. //"__forceinline" and MSVC seems to have some bugs in old versions and in debug mode
  54. #define BOOST_MOVE_FORCEINLINE inline
  55. #elif defined(BOOST_CLANG) || (defined(BOOST_GCC) && ((__GNUC__ <= 5) || defined(__MINGW32__)))
  56. //Older GCCs have problems with forceinline
  57. //Clang can have code bloat issues with forceinline, see
  58. //https://lists.boost.org/boost-users/2023/04/91445.php and
  59. //https://github.com/llvm/llvm-project/issues/62202
  60. #define BOOST_MOVE_FORCEINLINE inline
  61. #else
  62. #define BOOST_MOVE_FORCEINLINE BOOST_FORCEINLINE
  63. #endif
  64. namespace boost {
  65. namespace movelib {
  66. template <typename T1>
  67. BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore(T1 const&)
  68. {}
  69. }} //namespace boost::movelib {
  70. #if !(defined BOOST_NO_EXCEPTIONS)
  71. # define BOOST_MOVE_TRY { try
  72. # define BOOST_MOVE_CATCH(x) catch(x)
  73. # define BOOST_MOVE_RETHROW throw;
  74. # define BOOST_MOVE_CATCH_END }
  75. #else
  76. # if !defined(BOOST_MSVC) || BOOST_MSVC >= 1900
  77. # define BOOST_MOVE_TRY { if (true)
  78. # define BOOST_MOVE_CATCH(x) else if (false)
  79. # else
  80. // warning C4127: conditional expression is constant
  81. # define BOOST_MOVE_TRY { \
  82. __pragma(warning(push)) \
  83. __pragma(warning(disable: 4127)) \
  84. if (true) \
  85. __pragma(warning(pop))
  86. # define BOOST_MOVE_CATCH(x) else \
  87. __pragma(warning(push)) \
  88. __pragma(warning(disable: 4127)) \
  89. if (false) \
  90. __pragma(warning(pop))
  91. # endif
  92. # define BOOST_MOVE_RETHROW
  93. # define BOOST_MOVE_CATCH_END }
  94. #endif
  95. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  96. # ifndef BOOST_NO_CXX11_VARIADIC_MACROS
  97. # define BOOST_MOVE_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
  98. # else
  99. # define BOOST_MOVE_STATIC_ASSERT( B ) static_assert(B, #B)
  100. # endif
  101. #else
  102. namespace boost {
  103. namespace move_detail {
  104. template<bool B>
  105. struct STATIC_ASSERTION_FAILURE;
  106. template<>
  107. struct STATIC_ASSERTION_FAILURE<true>{};
  108. template<unsigned> struct static_assert_test {};
  109. }}
  110. #define BOOST_MOVE_STATIC_ASSERT(B) \
  111. typedef ::boost::move_detail::static_assert_test<\
  112. (unsigned)sizeof(::boost::move_detail::STATIC_ASSERTION_FAILURE<bool(B)>)>\
  113. BOOST_JOIN(boost_move_static_assert_typedef_, __LINE__) BOOST_ATTRIBUTE_UNUSED
  114. #endif
  115. #if !defined(__has_cpp_attribute) || defined(__CUDACC__)
  116. #define BOOST_MOVE_HAS_MSVC_ATTRIBUTE(ATTR) 0
  117. #else
  118. #define BOOST_MOVE_HAS_MSVC_ATTRIBUTE(ATTR) __has_cpp_attribute(msvc::ATTR)
  119. #endif
  120. // See https://devblogs.microsoft.com/cppblog/improving-the-state-of-debug-performance-in-c/
  121. // for details on how MSVC has improved debug experience, specifically for move/forward-like utilities
  122. #if BOOST_MOVE_HAS_MSVC_ATTRIBUTE(intrinsic)
  123. #define BOOST_MOVE_INTRINSIC_CAST [[msvc::intrinsic]]
  124. #else
  125. #define BOOST_MOVE_INTRINSIC_CAST BOOST_MOVE_FORCEINLINE
  126. #endif
  127. #endif //#ifndef BOOST_MOVE_DETAIL_WORKAROUND_HPP