/Src/Dependencies/Boost/boost/static_assert.hpp

http://hadesmem.googlecode.com/ · C++ Header · 138 lines · 69 code · 20 blank · 49 comment · 13 complexity · 5d191e40d6b154f01136a3699737cc5f MD5 · raw file

  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. // See http://www.boost.org/libs/static_assert for documentation.
  6. /*
  7. Revision history:
  8. 02 August 2000
  9. Initial version.
  10. */
  11. #ifndef BOOST_STATIC_ASSERT_HPP
  12. #define BOOST_STATIC_ASSERT_HPP
  13. #include <boost/config.hpp>
  14. #include <boost/detail/workaround.hpp>
  15. #ifndef BOOST_NO_STATIC_ASSERT
  16. # define BOOST_STATIC_ASSERT_MSG( B, Msg ) static_assert(B, Msg)
  17. #else
  18. # define BOOST_STATIC_ASSERT_MSG( B, Msg ) BOOST_STATIC_ASSERT( B )
  19. #endif
  20. #ifdef __BORLANDC__
  21. //
  22. // workaround for buggy integral-constant expression support:
  23. #define BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS
  24. #endif
  25. #if defined(__GNUC__) && (__GNUC__ == 3) && ((__GNUC_MINOR__ == 3) || (__GNUC_MINOR__ == 4))
  26. // gcc 3.3 and 3.4 don't produce good error messages with the default version:
  27. # define BOOST_SA_GCC_WORKAROUND
  28. #endif
  29. //
  30. // If the compiler issues warnings about old C style casts,
  31. // then enable this:
  32. //
  33. #if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)))
  34. # define BOOST_STATIC_ASSERT_BOOL_CAST( x ) ((x) == 0 ? false : true)
  35. #else
  36. # define BOOST_STATIC_ASSERT_BOOL_CAST(x) (bool)(x)
  37. #endif
  38. #ifndef BOOST_NO_STATIC_ASSERT
  39. # define BOOST_STATIC_ASSERT( B ) static_assert(B, #B)
  40. #else
  41. namespace boost{
  42. // HP aCC cannot deal with missing names for template value parameters
  43. template <bool x> struct STATIC_ASSERTION_FAILURE;
  44. template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
  45. // HP aCC cannot deal with missing names for template value parameters
  46. template<int x> struct static_assert_test{};
  47. }
  48. //
  49. // Implicit instantiation requires that all member declarations be
  50. // instantiated, but that the definitions are *not* instantiated.
  51. //
  52. // It's not particularly clear how this applies to enum's or typedefs;
  53. // both are described as declarations [7.1.3] and [7.2] in the standard,
  54. // however some compilers use "delayed evaluation" of one or more of
  55. // these when implicitly instantiating templates. We use typedef declarations
  56. // by default, but try defining BOOST_USE_ENUM_STATIC_ASSERT if the enum
  57. // version gets better results from your compiler...
  58. //
  59. // Implementation:
  60. // Both of these versions rely on sizeof(incomplete_type) generating an error
  61. // message containing the name of the incomplete type. We use
  62. // "STATIC_ASSERTION_FAILURE" as the type name here to generate
  63. // an eye catching error message. The result of the sizeof expression is either
  64. // used as an enum initialiser, or as a template argument depending which version
  65. // is in use...
  66. // Note that the argument to the assert is explicitly cast to bool using old-
  67. // style casts: too many compilers currently have problems with static_cast
  68. // when used inside integral constant expressions.
  69. //
  70. #if !defined(BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS)
  71. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  72. // __LINE__ macro broken when -ZI is used see Q199057
  73. // fortunately MSVC ignores duplicate typedef's.
  74. #define BOOST_STATIC_ASSERT( B ) \
  75. typedef ::boost::static_assert_test<\
  76. sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)\
  77. > boost_static_assert_typedef_
  78. #elif defined(BOOST_MSVC)
  79. #define BOOST_STATIC_ASSERT( B ) \
  80. typedef ::boost::static_assert_test<\
  81. sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST ( B ) >)>\
  82. BOOST_JOIN(boost_static_assert_typedef_, __COUNTER__)
  83. #elif defined(BOOST_INTEL_CXX_VERSION) || defined(BOOST_SA_GCC_WORKAROUND)
  84. // agurt 15/sep/02: a special care is needed to force Intel C++ issue an error
  85. // instead of warning in case of failure
  86. # define BOOST_STATIC_ASSERT( B ) \
  87. typedef char BOOST_JOIN(boost_static_assert_typedef_, __LINE__) \
  88. [ ::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >::value ]
  89. #elif defined(__sgi)
  90. // special version for SGI MIPSpro compiler
  91. #define BOOST_STATIC_ASSERT( B ) \
  92. BOOST_STATIC_CONSTANT(bool, \
  93. BOOST_JOIN(boost_static_assert_test_, __LINE__) = ( B )); \
  94. typedef ::boost::static_assert_test<\
  95. sizeof(::boost::STATIC_ASSERTION_FAILURE< \
  96. BOOST_JOIN(boost_static_assert_test_, __LINE__) >)>\
  97. BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
  98. #elif BOOST_WORKAROUND(__MWERKS__, <= 0x3003)
  99. // special version for CodeWarrior <= 8.x
  100. #define BOOST_STATIC_ASSERT( B ) \
  101. BOOST_STATIC_CONSTANT(int, \
  102. BOOST_JOIN(boost_static_assert_test_, __LINE__) = \
  103. sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >) )
  104. #else
  105. // generic version
  106. #define BOOST_STATIC_ASSERT( B ) \
  107. typedef ::boost::static_assert_test<\
  108. sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >)>\
  109. BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
  110. #endif
  111. #else
  112. // alternative enum based implementation:
  113. #define BOOST_STATIC_ASSERT( B ) \
  114. enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
  115. = sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) }
  116. #endif
  117. #endif // defined(BOOST_NO_STATIC_ASSERT)
  118. #endif // BOOST_STATIC_ASSERT_HPP