|
Boost Users : |
From: Michiel Helvensteijn (m.helvensteijn_at_[hidden])
Date: 2008-07-08 21:52:12
I've been using the BOOST_ASSERT macro. I like it because it can throw an
exception rather than use the abort signal. And I can catch exceptions in
automated unit-tests.
However, I sometimes use assert(false) in locations that should be
unreachable. And the compiler (well, GCC at least) understands this,
because assert() calls abort() if the expression equals (evaluates to)
false.
If I use BOOST_ASSERT in this way, the compiler shows me various warnings
about the flow of control. It does not know that my implementation of
assertion_failed() throws an exception.
To get rid of those warnings, I've changed BOOST_ASSERT for my personal use:
#define BOOST_ASSERT(expr) { \
if (!(expr)) { \
::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, \
__FILE__, __LINE__); \
abort(); \
} \
}
It may not be the best way. For example, there may have been a reason to
push everything into the ternary operator that I am not aware of. But it
seems to work.
I believe this functionality should be part of the library. Probably
optional by defining another constant (BOOST_ENABLE_ASSERT_ABORT or
somesuch).
Are the developers aware of this problem?
Do you think it will be solved in the library?
Thanks in advance for your reply,
-- Michiel Helvensteijn
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net