mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 14:04:26 +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 logic_error_called = false;
|
||||||
static bool runtime_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
|
//User defined throw implementations
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace container {
|
namespace container {
|
||||||
|
|
||||||
void throw_bad_alloc()
|
BOOST_NORETURN void throw_bad_alloc()
|
||||||
{ bad_alloc_called = true; }
|
{
|
||||||
|
bad_alloc_called = true;
|
||||||
|
throw_out_of_range("dummy");
|
||||||
|
}
|
||||||
|
|
||||||
void throw_out_of_range(const char* str)
|
BOOST_NORETURN void throw_out_of_range(const char* str)
|
||||||
{ (void)str; out_of_range_called = true; }
|
{
|
||||||
|
out_of_range_called = true;
|
||||||
|
throw_length_error(str);
|
||||||
|
}
|
||||||
|
|
||||||
void throw_length_error(const char* str)
|
BOOST_NORETURN void throw_length_error(const char* str)
|
||||||
{ (void)str; length_error_called = true; }
|
{
|
||||||
|
length_error_called = true;
|
||||||
|
throw_logic_error(str);
|
||||||
|
}
|
||||||
|
|
||||||
void throw_logic_error(const char* str)
|
BOOST_NORETURN void throw_logic_error(const char* str)
|
||||||
{ (void)str; logic_error_called = true; }
|
{
|
||||||
|
logic_error_called = true;
|
||||||
|
throw_runtime_error(str);
|
||||||
|
}
|
||||||
|
|
||||||
void throw_runtime_error(const char* str)
|
BOOST_NORETURN void throw_runtime_error(const char* str)
|
||||||
{ (void)str; runtime_error_called = true; }
|
{
|
||||||
|
(void)str;
|
||||||
|
runtime_error_called = true;
|
||||||
|
validate_and_never_return();
|
||||||
|
}
|
||||||
|
|
||||||
}} //boost::container
|
}} //boost::container
|
||||||
|
|
||||||
@@ -47,16 +73,8 @@ int main()
|
|||||||
{
|
{
|
||||||
//Check user-defined throw callbacks are called
|
//Check user-defined throw callbacks are called
|
||||||
throw_bad_alloc();
|
throw_bad_alloc();
|
||||||
BOOST_TEST(bad_alloc_called == true);
|
//Never reached
|
||||||
throw_out_of_range("dummy");
|
std::abort();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <boost/container/detail/config_end.hpp>
|
#include <boost/container/detail/config_end.hpp>
|
||||||
|
Reference in New Issue
Block a user