From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 576AA385771C; Mon, 21 Aug 2023 09:44:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 576AA385771C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692611064; bh=x/jdve+eSCOoAK9ktJlthytr38cZ73aiLqOPinQC+CM=; h=From:To:Subject:Date:From; b=ixtyyLt0VvqSUW6OH1uMnQYqi/EIWe+AOk5JTq9HwS2J2YLM+wmh6aA41jkDjRx1Y tRdd0WQSDkyjy1mb+wdXQvLLf0tA+Sp6iXM9BPsYsXNXhoF4bt5wT7oG3Gt4F2MOfN DyJzjxTQfwt3eaZvba8oVn4eemIsFLpxilq02uzE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-3353] libstdc++: Remove reliance on unspecified behaviour in std::rethrow_if_nested test X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: d5dfba19aee783a6ba90fdba1993d576c7ec310b X-Git-Newrev: 03cb6904d1ab6de1f42d06bcf2988bf7b3e7709a Message-Id: <20230821094424.576AA385771C@sourceware.org> Date: Mon, 21 Aug 2023 09:44:24 +0000 (GMT) List-Id: https://gcc.gnu.org/g:03cb6904d1ab6de1f42d06bcf2988bf7b3e7709a commit r14-3353-g03cb6904d1ab6de1f42d06bcf2988bf7b3e7709a Author: Jonathan Wakely Date: Mon Aug 21 10:36:13 2023 +0100 libstdc++: Remove reliance on unspecified behaviour in std::rethrow_if_nested test This test case calls std::set_terminate while there is an active exception. Since LWG 2111 it is unspecified which terminate handler is used when std::nested_exception::rethrow_nested() calls std::terminate. With libsupc++ the global handler changed by std::set_terminate is used, but libc++abi uses the active exception's handler (the one that was current when the exception was first thrown). Adjust the test case so that it works with either implementation choice. So that the process doesn't exit cleanly if std::terminate happens sooner than expected, use a global variable to control when the "clean terminate" behaviour happens. libstdc++-v3/ChangeLog: * testsuite/18_support/nested_exception/rethrow_if_nested-term.cc: Call std::set_terminate before throwing the nested exception. Diff: --- .../18_support/nested_exception/rethrow_if_nested-term.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 3bfc7ab99436..b221eea3178f 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)