mirror of
https://github.com/boostorg/container.git
synced 2025-08-01 21:44:27 +02:00
Update throw tests to avoid segmentation violation
This commit is contained in:
@@ -22,24 +22,50 @@ static bool length_error_called = false;
|
||||
static bool logic_error_called = false;
|
||||
static bool runtime_error_called = false;
|
||||
|
||||
BOOST_NORETURN static void validate_and_never_return()
|
||||
{
|
||||
BOOST_TEST(bad_alloc_called == true);
|
||||
BOOST_TEST(out_of_range_called == true);
|
||||
BOOST_TEST(length_error_called == true);
|
||||
BOOST_TEST(logic_error_called == true);
|
||||
BOOST_TEST(runtime_error_called == true);
|
||||
std::exit(::boost::report_errors());
|
||||
}
|
||||
|
||||
//User defined throw implementations
|
||||
namespace boost {
|
||||
namespace container {
|
||||
|
||||
void throw_bad_alloc()
|
||||
{ bad_alloc_called = true; }
|
||||
BOOST_NORETURN void throw_bad_alloc()
|
||||
{
|
||||
bad_alloc_called = true;
|
||||
throw_out_of_range("dummy");
|
||||
}
|
||||
|
||||
void throw_out_of_range(const char* str)
|
||||
{ (void)str; out_of_range_called = true; }
|
||||
BOOST_NORETURN void throw_out_of_range(const char* str)
|
||||
{
|
||||
out_of_range_called = true;
|
||||
throw_length_error(str);
|
||||
}
|
||||
|
||||
void throw_length_error(const char* str)
|
||||
{ (void)str; length_error_called = true; }
|
||||
BOOST_NORETURN void throw_length_error(const char* str)
|
||||
{
|
||||
length_error_called = true;
|
||||
throw_logic_error(str);
|
||||
}
|
||||
|
||||
void throw_logic_error(const char* str)
|
||||
{ (void)str; logic_error_called = true; }
|
||||
BOOST_NORETURN void throw_logic_error(const char* str)
|
||||
{
|
||||
logic_error_called = true;
|
||||
throw_runtime_error(str);
|
||||
}
|
||||
|
||||
void throw_runtime_error(const char* str)
|
||||
{ (void)str; runtime_error_called = true; }
|
||||
BOOST_NORETURN void throw_runtime_error(const char* str)
|
||||
{
|
||||
(void)str;
|
||||
runtime_error_called = true;
|
||||
validate_and_never_return();
|
||||
}
|
||||
|
||||
}} //boost::container
|
||||
|
||||
@@ -47,16 +73,8 @@ int main()
|
||||
{
|
||||
//Check user-defined throw callbacks are called
|
||||
throw_bad_alloc();
|
||||
BOOST_TEST(bad_alloc_called == true);
|
||||
throw_out_of_range("dummy");
|
||||
BOOST_TEST(out_of_range_called == true);
|
||||
throw_length_error("dummy");
|
||||
BOOST_TEST(length_error_called == true);
|
||||
throw_logic_error("dummy");
|
||||
BOOST_TEST(logic_error_called == true);
|
||||
throw_runtime_error("dummy");
|
||||
BOOST_TEST(runtime_error_called == true);
|
||||
return ::boost::report_errors();
|
||||
//Never reached
|
||||
std::abort();
|
||||
}
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
|
Reference in New Issue
Block a user