Boost logo

Boost :

From: Vesa Karvonen (vesa.karvonen_at_[hidden])
Date: 2001-05-24 11:24:51


I understand the desire to make the compiler error message readable when a
static assertion fails. I tried various techniques myself a long time ago
(1998). Unfortunately, every technique I tried, was simply too brittle on
some compiler, so in the end I decided to revert to a variation (typedef
illegal array size) of the Van Horn technique. After that I've not
encountered major problems with my static assertion.

IMO it is not imperative to make the compiler error message readable,
because on a productive programming environment, you can jump to the point
of the error with a maximum of one keystroke (if your programming
environment doesn't have that capability then someone else will have your
lunch in the near future), where you can read the complete static assertion
with just the amount of nicely formatted comments that you like:

    STATIC_ASSERT(expression); // nicely formatted comment

In summary, IMO the benefit of having a simple and robust implementation of
static assertion clearly outweighs the benefit of having a verbose but
brittle static assertion. Now that the boost static assertion has been shown
not to work in some situations, I think that research on this should be
primarily targeted on finding an implementation that works on as many
compilers as possible.

With that said, I know that at least MSVC fails to compile almost any kind
of static assertion in certain situations - including the static assert I'm
using. On those situations I have used various workarounds, such as placing
the static assertion inside a function rather than the class where it would
ideally belong.

----- Original Message -----
From: "Beman Dawes" <bdawes_at_[hidden]>
To: "Boost.org mailing list" <boost_at_[hidden]>
Sent: Thursday, May 24, 2001 18:39
Subject: [boost] BOOST_STATIC_ASSERT question

> This program works as expected with the GNU, Metrowerks, and Microsoft
> compilers:
>
> #include <iostream>
> #include <boost/static_assert.hpp>
>
> template< typename T >
> void f( T & t )
> {
> std::cout << sizeof(T) << "\n";
> BOOST_STATIC_ASSERT( sizeof(T) ); // line in question
> }
>
> int main()
> {
> long l;
> f(l);
> return 0;
> }
>
> With the Borland 5.5.1 and Intel 5.0 compilers, the BOOST_STATIC_ASSERT
> fails:
>
> Borland:
> Error E2450 c:/boost/site/libs/smart_ptr/test.cpp 8: Undefined structure
> 'boost:
> :STATIC_ASSERTION_FAILURE<4>' in function f<long>(long &)
> Error E2109 c:/boost/site/libs/smart_ptr/test.cpp 8: Not an allowed type
in
> func
> tion f<long>(long &)
>
> Intel:
> c:/boost/site/libs/smart_ptr/test.cpp(8) : error #70: incomplete type is
> not allowed
> BOOST_STATIC_ASSERT( sizeof(T) );
> ^
> detected during instantiation of "void f(T &) [with T=long]"
>
> Are these compilers wrong, or is there a problem with BOOST_STATIC_ASSERT?
>
> (Both produce the expected output if the line in question is commented
> out.)
>
> --Beman


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