Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2006-07-04 09:12:43


On Sat, 24 Jun 2006 14:17:37 +0200, Gennaro Prota
<gennaro_prota_at_[hidden]> wrote:

>Tricky question. IMHO it is undefined behavior. When BOOST_ASSERT
>falls back to the standard assert it really depends on the underlying
>library. C90 does not require that assert works with expressions
>having non-int type. In C99 it shall work for any scalar expression
>(which anyway "out of range" is not; it has array type).
>
>We could perhaps protect against this kinds of things by using a
>static_cast in assert.hpp (probably documenting that)

I'd like to fix this problem. But I guess I should better explain that
"perhaps". The static_cast would prevent using, for instance

 BOOST_STATIC_ASSERT("foo");

That's fine as long as we want the user to "perceive" the problem and
be forced to write, for instance:

 BOOST_STATIC_ASSERT("foo" != 0 /*or nullptr*/);

Otherwise the following choices come to mind:

a) # define BOOST_ASSERT(expr) assert(0 != (expr))
b) # define BOOST_ASSERT(expr) assert(!!(expr))
c) # define BOOST_ASSERT(expr) assert("BOOST_LIBRARIES:" && (expr))
d) # define BOOST_ASSERT(expr) assert(!"BOOST_LIBRARIES:" || (expr))

The last one is for those who find "||" to be a better "separator"
than "&&" :-o

Looking forward for consensus and patching :)

--
[ Gennaro Prota, C++ developer for hire ]
[    resume:  available on request      ]

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