Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2005-05-16 04:27:33


>> That should be 14.7.1 :-) I've added a test to static_assert to see if
>> other compilers have this problem.
>>
>> This failure only worries me because it's likely hiding either a bunch of
>> other failures, or successes. So if anyone has some idea on how to make a
>> macro generate different code based on function or non-function context I
>> would _love_ to know.
>
> Aha, fixed it!!
>
> There is now a custom version of static_assert for CW-8.x:
>
> // special version for CodeWarrior <= 8.x
> #define BOOST_STATIC_ASSERT( B ) \
> BOOST_STATIC_CONSTANT(int, \
> BOOST_JOIN(boost_static_assert_test_, __LINE__) = \
> sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) )
>
> Which, for example, translates to:
>
> static const int boost_static_assert_test_10 =
> sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( N < 2 ) >) ;
>
> This forces the template instantiation on both function and non-function
> context. So for the first time all static_assert tests pass for this
> compiler :-) -- And this should also clear all the Spirit tests.

As you've noticed already, if a static assert appears on the same line in
two different files then you get a redefinition error. I don't suppose CW
supports __COUNTER__ like MSVC does, if so we could give each a unique name?
Failing that, there is a recommendation in the static assert docs, that
users take care to place static asserts on separate lines (some compilers
can't cope with duplicate typedefs, even though they are allowed in the
language), can spirit be re-jigged to do that?

John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk