Boost logo

Boost :

From: Marcin Kalicinski (kalita_at_[hidden])
Date: 2005-09-19 08:46:08


> > Have you considered modifying BOOST_ASSERT to use __assume on MSVC?
> > (...) Microsoft docs for __assume are here:
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/msmod_36.asp

"Dave Harris" <brangdon_at_[hidden]> wrote
> (...) I suggest we add a new macro, eg named BOOST_ASSUME(x),
> which expands to BOOST_ASSERT(x) by default and to __assume(x) when
> BOOST_DISABLE_ASSERTS is true. This latter case would be documented as
> causing undefined behaviour if x is false.

I think generally this is a good idea, but it has a small problem. I would
expect that BOOST_ASSUME should turn into __assume when compiled in
"release" mode of MSVC. As of above proposed solution this is not the case -
user additionally needs to define BOOST_DISABLE_ASSERTS to get __assume. So
when NDEBUG is defined and BOOST_DISABLE_ASSERTS is not (I think this is 99%
of cases, because few people actually use BOOST_DISABLE_ASSERTS),
BOOST_ASSUME will expand to BOOST_ASSERT and the whole thing will be
useless.

I think we should rather base on NDEBUG macro, the same that determines the
behavior of assert. The whole change then boils down to adding these 6 lines
at the end of assert.hpp:

#include <boost/config.hpp>
#if defined(BOOST_MSVC) && defined(NDEBUG)
# define BOOST_ASSUME(e) { BOOST_ASSERT(e); if (e); else __assume(0); }
#else
# define BOOST_ASSUME(e) BOOST_ASSERT(e)
#endif

Please let me know what you think.

There's also a question what should BOOST_ENABLE_ASSERT_HANDLER do with
BOOST_ASSUME? Should it invoke the handler if condition is false? I would
say yes, and the above code will do just that.

Marcin


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