diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested-term.cc b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested-term.cc index 3bfc7ab9943..b221eea3178 100644 --- a/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested-term.cc +++ b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested-term.cc @@ -4,25 +4,33 @@ #include #include -[[noreturn]] void terminate_cleanly() noexcept { std::exit(0); } +int exit_status = 1; +[[noreturn]] void terminate_cleanly() noexcept { std::exit(exit_status); } struct A { virtual ~A() = default; }; int main() { + std::set_terminate(terminate_cleanly); try { // At this point std::current_exception() == nullptr so the // std::nested_exception object is empty. std::throw_with_nested(A{}); + + // Should not reach this point. + std::abort(); } catch (const A& a) { - std::set_terminate(terminate_cleanly); + // This means the expected std::terminate() call will exit cleanly, + // so this test will PASS. + exit_status = 0; + std::rethrow_if_nested(a); #if __cpp_rtti // No nested exception, so trying to rethrow it calls std::terminate() - // which calls std::exit(0). Shoud not reach this point. + // which calls std::exit(0). Should not reach this point. std::abort(); #else // Without RTTI we can't dynamic_cast(&a)