Blame boost/static_assert.hpp

Packit 58578d
//  (C) Copyright John Maddock 2000.
Packit 58578d
//  Use, modification and distribution are subject to the 
Packit 58578d
//  Boost Software License, Version 1.0. (See accompanying file 
Packit 58578d
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Packit 58578d
Packit 58578d
//  See http://www.boost.org/libs/static_assert for documentation.
Packit 58578d
Packit 58578d
/*
Packit 58578d
 Revision history:
Packit 58578d
   02 August 2000
Packit 58578d
      Initial version.
Packit 58578d
*/
Packit 58578d
Packit 58578d
#ifndef BOOST_STATIC_ASSERT_HPP
Packit 58578d
#define BOOST_STATIC_ASSERT_HPP
Packit 58578d
Packit 58578d
#include <boost/config.hpp>
Packit 58578d
#include <boost/detail/workaround.hpp>
Packit 58578d
Packit 58578d
#if defined(__GNUC__) && !defined(__GXX_EXPERIMENTAL_CXX0X__)
Packit 58578d
//
Packit 58578d
// This is horrible, but it seems to be the only we can shut up the
Packit 58578d
// "anonymous variadic macros were introduced in C99 [-Wvariadic-macros]"
Packit 58578d
// warning that get spewed out otherwise in non-C++11 mode.
Packit 58578d
//
Packit 58578d
#pragma GCC system_header
Packit 58578d
#endif
Packit 58578d
Packit 58578d
#ifndef BOOST_NO_CXX11_STATIC_ASSERT
Packit 58578d
#  ifndef BOOST_NO_CXX11_VARIADIC_MACROS
Packit 58578d
#     define BOOST_STATIC_ASSERT_MSG( ... ) static_assert(__VA_ARGS__)
Packit 58578d
#  else
Packit 58578d
#     define BOOST_STATIC_ASSERT_MSG( B, Msg ) static_assert( B, Msg )
Packit 58578d
#  endif
Packit 58578d
#else
Packit 58578d
#     define BOOST_STATIC_ASSERT_MSG( B, Msg ) BOOST_STATIC_ASSERT( B )
Packit 58578d
#endif
Packit 58578d
Packit 58578d
#ifdef __BORLANDC__
Packit 58578d
//
Packit 58578d
// workaround for buggy integral-constant expression support:
Packit 58578d
#define BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS
Packit 58578d
#endif
Packit 58578d
Packit 58578d
#if defined(__GNUC__) && (__GNUC__ == 3) && ((__GNUC_MINOR__ == 3) || (__GNUC_MINOR__ == 4))
Packit 58578d
// gcc 3.3 and 3.4 don't produce good error messages with the default version:
Packit 58578d
#  define BOOST_SA_GCC_WORKAROUND
Packit 58578d
#endif
Packit 58578d
Packit 58578d
//
Packit 58578d
// If the compiler issues warnings about old C style casts,
Packit 58578d
// then enable this:
Packit 58578d
//
Packit 58578d
#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)))
Packit 58578d
#  ifndef BOOST_NO_CXX11_VARIADIC_MACROS
Packit 58578d
#     define BOOST_STATIC_ASSERT_BOOL_CAST( ... ) ((__VA_ARGS__) == 0 ? false : true)
Packit 58578d
#  else
Packit 58578d
#     define BOOST_STATIC_ASSERT_BOOL_CAST( x ) ((x) == 0 ? false : true)
Packit 58578d
#  endif
Packit 58578d
#else
Packit 58578d
#  ifndef BOOST_NO_CXX11_VARIADIC_MACROS
Packit 58578d
#     define BOOST_STATIC_ASSERT_BOOL_CAST( ... ) (bool)(__VA_ARGS__)
Packit 58578d
#  else
Packit 58578d
#     define BOOST_STATIC_ASSERT_BOOL_CAST(x) (bool)(x)
Packit 58578d
#  endif
Packit 58578d
#endif
Packit 58578d
Packit 58578d
#ifndef BOOST_NO_CXX11_STATIC_ASSERT
Packit 58578d
#  ifndef BOOST_NO_CXX11_VARIADIC_MACROS
Packit 58578d
#     define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
Packit 58578d
#  else
Packit 58578d
#     define BOOST_STATIC_ASSERT( B ) static_assert(B, #B)
Packit 58578d
#  endif
Packit 58578d
#else
Packit 58578d
Packit 58578d
namespace boost{
Packit 58578d
Packit 58578d
// HP aCC cannot deal with missing names for template value parameters
Packit 58578d
template <bool x> struct STATIC_ASSERTION_FAILURE;
Packit 58578d
Packit 58578d
template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
Packit 58578d
Packit 58578d
// HP aCC cannot deal with missing names for template value parameters
Packit 58578d
template<int x> struct static_assert_test{};
Packit 58578d
Packit 58578d
}
Packit 58578d
Packit 58578d
//
Packit 58578d
// Implicit instantiation requires that all member declarations be
Packit 58578d
// instantiated, but that the definitions are *not* instantiated.
Packit 58578d
//
Packit 58578d
// It's not particularly clear how this applies to enum's or typedefs;
Packit 58578d
// both are described as declarations [7.1.3] and [7.2] in the standard,
Packit 58578d
// however some compilers use "delayed evaluation" of one or more of
Packit 58578d
// these when implicitly instantiating templates.  We use typedef declarations
Packit 58578d
// by default, but try defining BOOST_USE_ENUM_STATIC_ASSERT if the enum
Packit 58578d
// version gets better results from your compiler...
Packit 58578d
//
Packit 58578d
// Implementation:
Packit 58578d
// Both of these versions rely on sizeof(incomplete_type) generating an error
Packit 58578d
// message containing the name of the incomplete type.  We use
Packit 58578d
// "STATIC_ASSERTION_FAILURE" as the type name here to generate
Packit 58578d
// an eye catching error message.  The result of the sizeof expression is either
Packit 58578d
// used as an enum initialiser, or as a template argument depending which version
Packit 58578d
// is in use...
Packit 58578d
// Note that the argument to the assert is explicitly cast to bool using old-
Packit 58578d
// style casts: too many compilers currently have problems with static_cast
Packit 58578d
// when used inside integral constant expressions.
Packit 58578d
//
Packit 58578d
#if !defined(BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS)
Packit 58578d
Packit 58578d
#if defined(BOOST_MSVC) && defined(BOOST_NO_CXX11_VARIADIC_MACROS)
Packit 58578d
#define BOOST_STATIC_ASSERT( B ) \
Packit 58578d
   typedef ::boost::static_assert_test<\
Packit 58578d
      sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST ( B ) >)>\
Packit 58578d
         BOOST_JOIN(boost_static_assert_typedef_, __COUNTER__)
Packit 58578d
#elif defined(BOOST_MSVC)
Packit 58578d
#define BOOST_STATIC_ASSERT(...) \
Packit 58578d
   typedef ::boost::static_assert_test<\
Packit 58578d
      sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST (__VA_ARGS__) >)>\
Packit 58578d
         BOOST_JOIN(boost_static_assert_typedef_, __COUNTER__)
Packit 58578d
#elif (defined(BOOST_INTEL_CXX_VERSION) || defined(BOOST_SA_GCC_WORKAROUND))  && defined(BOOST_NO_CXX11_VARIADIC_MACROS)
Packit 58578d
// agurt 15/sep/02: a special care is needed to force Intel C++ issue an error 
Packit 58578d
// instead of warning in case of failure
Packit 58578d
# define BOOST_STATIC_ASSERT( B ) \
Packit 58578d
    typedef char BOOST_JOIN(boost_static_assert_typedef_, __LINE__) \
Packit 58578d
        [ ::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >::value ]
Packit 58578d
#elif (defined(BOOST_INTEL_CXX_VERSION) || defined(BOOST_SA_GCC_WORKAROUND))  && !defined(BOOST_NO_CXX11_VARIADIC_MACROS)
Packit 58578d
// agurt 15/sep/02: a special care is needed to force Intel C++ issue an error 
Packit 58578d
// instead of warning in case of failure
Packit 58578d
# define BOOST_STATIC_ASSERT(...) \
Packit 58578d
    typedef char BOOST_JOIN(boost_static_assert_typedef_, __LINE__) \
Packit 58578d
        [ ::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( __VA_ARGS__ ) >::value ]
Packit 58578d
#elif defined(__sgi)
Packit 58578d
// special version for SGI MIPSpro compiler
Packit 58578d
#define BOOST_STATIC_ASSERT( B ) \
Packit 58578d
   BOOST_STATIC_CONSTANT(bool, \
Packit 58578d
     BOOST_JOIN(boost_static_assert_test_, __LINE__) = ( B )); \
Packit 58578d
   typedef ::boost::static_assert_test<\
Packit 58578d
     sizeof(::boost::STATIC_ASSERTION_FAILURE< \
Packit 58578d
       BOOST_JOIN(boost_static_assert_test_, __LINE__) >)>\
Packit 58578d
         BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
Packit 58578d
#elif BOOST_WORKAROUND(__MWERKS__, <= 0x3003)
Packit 58578d
// special version for CodeWarrior <= 8.x
Packit 58578d
#define BOOST_STATIC_ASSERT( B ) \
Packit 58578d
   BOOST_STATIC_CONSTANT(int, \
Packit 58578d
     BOOST_JOIN(boost_static_assert_test_, __LINE__) = \
Packit 58578d
       sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >) )
Packit 58578d
#else
Packit 58578d
// generic version
Packit 58578d
#  ifndef BOOST_NO_CXX11_VARIADIC_MACROS
Packit 58578d
#     define BOOST_STATIC_ASSERT( ... ) \
Packit 58578d
         typedef ::boost::static_assert_test<\
Packit 58578d
            sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( __VA_ARGS__ ) >)>\
Packit 58578d
               BOOST_JOIN(boost_static_assert_typedef_, __LINE__) BOOST_ATTRIBUTE_UNUSED
Packit 58578d
#  else
Packit 58578d
#     define BOOST_STATIC_ASSERT( B ) \
Packit 58578d
         typedef ::boost::static_assert_test<\
Packit 58578d
            sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >)>\
Packit 58578d
               BOOST_JOIN(boost_static_assert_typedef_, __LINE__) BOOST_ATTRIBUTE_UNUSED
Packit 58578d
#  endif
Packit 58578d
#endif
Packit 58578d
Packit 58578d
#else
Packit 58578d
// alternative enum based implementation:
Packit 58578d
#  ifndef BOOST_NO_CXX11_VARIADIC_MACROS
Packit 58578d
#    define BOOST_STATIC_ASSERT( ... ) \
Packit 58578d
         enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
Packit 58578d
            = sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( __VA_ARGS__ ) >) }
Packit 58578d
#  else
Packit 58578d
#    define BOOST_STATIC_ASSERT(B) \
Packit 58578d
         enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
Packit 58578d
            = sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) }
Packit 58578d
#  endif
Packit 58578d
#endif
Packit 58578d
#endif // defined(BOOST_NO_CXX11_STATIC_ASSERT)
Packit 58578d
Packit 58578d
#endif // BOOST_STATIC_ASSERT_HPP
Packit 58578d
Packit 58578d