Update throw tests to avoid segmentation violation

This commit is contained in:
Bo Rydberg
2019-12-05 17:49:58 +01:00
committed by GitHub
parent f7409fd6ed
commit 0fa5193cea

View File

@@ -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>