[Test] Funny Business with vector::at() out-of-range
I posted a question a couple of days ago: "Throws 'Escaping' both BOOST_CHECK_THROW and try{}". I found that BOOST_CHECK_EXCEPTION which is working for me elsewhere fails the same way. So, an out-of-range std::vector::at() seems to be the common element. In the definition of at(), the out-of-range response is handled by __throw_out_of_range_fmt(). When I looked up that one, I found void __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__)) __attribute__((__format__(__gnu_printf__, 1, 2))); in functexcept.h. To my admittedly less-than-expert eye, there doesn't seem to be an actual throw() here. On the other hand, the entire file are entries like this for various exceptions. There are a lot of Google hits for __throw_out_of_range_fmt, but they are for unresolved references in links, apparently caused by mixed version of libraries and object. Everything I've got is compiled linked for MinGW 64-bit, GCC 5.3.0, 64-bit --std=C++14, BOOST 1_60_1 64-bit so I get none of those errors. The problem I'm seeing with my test code is that wrapping a try{} around BOOST_CHECK_THROW shows that [1] the body of the try doesn't complete; but at the same time [2] not even a catch(...) can catch the presumed throw--as if a throw isn't actually being done. So, where did the throw go? Merrill Cornish
On 11/02/2016 07:52, Merrill Cornish wrote:
I posted a question a couple of days ago: "Throws 'Escaping' both BOOST_CHECK_THROW and try{}". I found that BOOST_CHECK_EXCEPTION which is working for me elsewhere fails the same way. So, an out-of-range std::vector::at() seems to be the common element.
In the definition of at(), the out-of-range response is handled by __throw_out_of_range_fmt(). When I looked up that one, I found
void __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__)) __attribute__((__format__(__gnu_printf__, 1, 2)));
in functexcept.h. To my admittedly less-than-expert eye, there doesn't seem to be an actual throw() here. On the other hand, the entire file are entries like this for various exceptions.
You've already found the answer to your original question in the other thread, but just FYI: These are just declarations, with the implementations in the library source rather than the headers. The implementation either throws (when exceptions are enabled) or calls abort() (when exceptions are disabled). The "noreturn" attribute indicates that they never return normally (they always throw or abort), which allows the compiler to make certain assumptions when optimising. Otherwise there's nothing special about these; they're just like any other function that throws -- as long as you don't disable exceptions. (And if it helps, if you did disable exceptions you would have seen a different error message than the one in your prior thread.)
participants (2)
-
Gavin Lambert
-
Merrill Cornish