Boost logo

Boost Users :

From: Richard Dingwall (rdingwall_at_[hidden])
Date: 2007-08-22 02:08:23


Hi there, I thought I'd post this because A) it might save someone a lot of
head-scratching and B) there aren't any posts on it already.

The short of it is, that if you have a setup similar to the following (i.e.,
an empty throw() clause on a template specialisation):

template<class output_type> output_type do_something(int input_value)
throw(std::invalid_argument);
template<> int do_something(int input_value) throw(std::invalid_argument);
template<> long do_something(int input_value) throw();

And attempt to test throwing a std::invalid_argument from within the long
specialised function, e.g.:

// note: an argument less than zero will throw a std::invalid_argument
BOOST_CHECK_THROW(do_something<long>(-1), std::invalid_argument);

You will see something the following:

Running 4 test cases...
terminate called after throwing an instance of 'std::invalid_argument'
  what(): Input value too low.
unknown location(0): fatal error in "long_throw": signal: SIGABRT
(application abort requested)
sigabrt_test_suite.cpp(58): last checkpoint

*** 1 failure detected in test suite "sigabrt tests"

My function is throwing a std::invalid_argument and my test case been
programmed to catch it. But it doesn't. This had me scratching my head for a
few days, until I noticed the empty throw() clause. Completing it resolved
the problem immediately.

I'm not sure if this is expected behaviour, but if anyone's interested, a
test case is attached. I'm using gcc version 4.0.1 (Apple Computer, Inc.
build 5367) on a G4 Powerbook with whatever was in Boost's SVN trunk on
August 6.

Cheers,

Richard





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