workaround.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2013. 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_INTRUSIVE_DETAIL_WORKAROUND_HPP
  11. #define BOOST_INTRUSIVE_DETAIL_WORKAROUND_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #ifndef BOOST_CONFIG_HPP
  19. #include <boost/config.hpp>
  20. #endif
  21. // MSVC-12 ICEs when variadic templates are enabled.
  22. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && (!defined(BOOST_MSVC) || BOOST_MSVC >= 1900)
  23. #define BOOST_INTRUSIVE_VARIADIC_TEMPLATES
  24. #endif
  25. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  26. #define BOOST_INTRUSIVE_PERFECT_FORWARDING
  27. #endif
  28. //Macros for documentation purposes. For code, expands to the argument
  29. #define BOOST_INTRUSIVE_IMPDEF(TYPE) TYPE
  30. #define BOOST_INTRUSIVE_SEEDOC(TYPE) TYPE
  31. #define BOOST_INTRUSIVE_DOC1ST(TYPE1, TYPE2) TYPE2
  32. #define BOOST_INTRUSIVE_I ,
  33. #define BOOST_INTRUSIVE_DOCIGN(T1) T1
  34. //#define BOOST_INTRUSIVE_DISABLE_FORCEINLINE
  35. #if defined(BOOST_INTRUSIVE_DISABLE_FORCEINLINE)
  36. #define BOOST_INTRUSIVE_FORCEINLINE inline
  37. #elif defined(BOOST_INTRUSIVE_FORCEINLINE_IS_BOOST_FORCELINE)
  38. #define BOOST_INTRUSIVE_FORCEINLINE BOOST_FORCEINLINE
  39. #elif defined(BOOST_MSVC) && (_MSC_VER < 1900 || defined(_DEBUG))
  40. //"__forceinline" and MSVC seems to have some bugs in old versions and in debug mode
  41. #define BOOST_INTRUSIVE_FORCEINLINE inline
  42. #elif defined(BOOST_CLANG) || (defined(BOOST_GCC) && ((__GNUC__ <= 5) || defined(__MINGW32__)))
  43. //Older GCCs have problems with forceinline
  44. //Clang can have code bloat issues with forceinline, see
  45. //https://lists.boost.org/boost-users/2023/04/91445.php and
  46. //https://github.com/llvm/llvm-project/issues/62202
  47. #define BOOST_INTRUSIVE_FORCEINLINE inline
  48. #else
  49. #define BOOST_INTRUSIVE_FORCEINLINE BOOST_FORCEINLINE
  50. #endif
  51. #if !(defined BOOST_NO_EXCEPTIONS)
  52. # define BOOST_INTRUSIVE_TRY { try
  53. # define BOOST_INTRUSIVE_CATCH(x) catch(x)
  54. # define BOOST_INTRUSIVE_RETHROW throw;
  55. # define BOOST_INTRUSIVE_CATCH_END }
  56. #else
  57. # if !defined(BOOST_MSVC) || BOOST_MSVC >= 1900
  58. # define BOOST_INTRUSIVE_TRY { if (true)
  59. # define BOOST_INTRUSIVE_CATCH(x) else if (false)
  60. # else
  61. // warning C4127: conditional expression is constant
  62. # define BOOST_INTRUSIVE_TRY { \
  63. __pragma(warning(push)) \
  64. __pragma(warning(disable: 4127)) \
  65. if (true) \
  66. __pragma(warning(pop))
  67. # define BOOST_INTRUSIVE_CATCH(x) else \
  68. __pragma(warning(push)) \
  69. __pragma(warning(disable: 4127)) \
  70. if (false) \
  71. __pragma(warning(pop))
  72. # endif
  73. # define BOOST_INTRUSIVE_RETHROW
  74. # define BOOST_INTRUSIVE_CATCH_END }
  75. #endif
  76. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  77. # ifndef BOOST_NO_CXX11_VARIADIC_MACROS
  78. # define BOOST_INTRUSIVE_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
  79. # else
  80. # define BOOST_INTRUSIVE_STATIC_ASSERT( B ) static_assert(B, #B)
  81. # endif
  82. #else
  83. namespace boost {
  84. namespace intrusive {
  85. namespace detail {
  86. template<bool B>
  87. struct STATIC_ASSERTION_FAILURE;
  88. template<>
  89. struct STATIC_ASSERTION_FAILURE<true>{};
  90. template<unsigned> struct static_assert_test {};
  91. }}}
  92. #define BOOST_INTRUSIVE_STATIC_ASSERT(B) \
  93. typedef ::boost::intrusive::detail::static_assert_test<\
  94. (unsigned)sizeof(::boost::intrusive::detail::STATIC_ASSERTION_FAILURE<bool(B)>)>\
  95. BOOST_JOIN(boost_intrusive_static_assert_typedef_, __LINE__) BOOST_ATTRIBUTE_UNUSED
  96. #endif
  97. #endif //#ifndef BOOST_INTRUSIVE_DETAIL_WORKAROUND_HPP