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