Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2007-02-25 10:50:20


I just did a sweep through all our code and found and fixed lots of
issues related to the use of BOOST_TEST macro, all of which boiled
down to the fact that it is possible to use it and never call
boost::report_errors(). In several places it had been used as a
drop-in replacement for assert(), which it isn't because failure to
call report_errors will allow test failures to pass silently. It was
also used in a couple places in lieu of BOOST_CHECK, i.e. the author
obviously was trying to use Boost.Test but got the wrong macro name.

I suggest we do something to make it harder to make that mistake. The
only approach I can think of is to create an object at namespace scope
whose destructor checks to see if we're exiting with a nonzero error
count and without having called report_errors. Or maybe it should
just do something like:

     namespace boost { namespace detail {
        template <bool = false>
        struct lightweight_error_reporter
        {
            ~lightweight_error_reporter()
            {
                if (boost::report_errors())
                {
                   abort();
                }
            }

            static lightweight_error_reporter instance;
        };
     }}
     

Whether abort() or exit(1) or throw xxx is more appropriate there I
don't know (haven't done the research).

Thoughts?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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