stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: static_assert config check
Date Thu, 12 Jun 2008 11:45:06 GMT
Travis Vitek wrote:
>  
> 
>> Eric Lemings wrote:
>>
>>
>> How's this for a suitable configuration check for static_assert?
>>
>> 	// compile-only test
>>
>> 	static_assert (sizeof (char) == 1, "impossible");
>>
>> 	template <int I> struct S {
>> 	    static_assert (I >= 0, "template parameter I must be
>> non-negative");
>> 	};
>>
> 
> I've written an errily similar test already (pasted below)
> 
> I think you should probably instantiate S somewhere and it might be a
> good idea put a line break before 'struct' so that your code conforms to
> our 'coding standards'. 
[...]

It's probably overkill, but just as an FYI, to verify this works
both ways the test would need to be negative, i.e., named NO_XXX,
and write #define _RWSTD_NO_XXX to stdout if the negative assert
failed to fire.

Martin

> template <int _N>
> struct S
> {
>     static_assert (0 < _N, "fail");
> };
> 
> template <int _N>
> void f ()
> {
>     static_assert (0 < _N, "fail");
> }
> 
> int main ()
> {
>     S<1> s1;
>     f<1>();
>     static_assert (1, "pass");
> 
>     return 0;
> }


Mime
View raw message