From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B24F0385771C for ; Mon, 21 Aug 2023 09:47:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B24F0385771C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692611224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gNInoSTMAtt1hmUcu6vhx8nuSq5+w7XgFFW1C8tLePg=; b=KXO16U94YJ5G86VXWoXvCPpbz6cs3Y/hSj78mOzm/I41QtRyzfuRM33CeMcCUVOS77R9VF sXKSzzjva7cjtmdHlPOviWk6Dzpx5qcXjyAOPM+s46sI6SoBUot4NirxiDqbDIHGJciFGr inDde0YDwjEMERvUDa60WqcNfXoMgxE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-295-toGBDc-7NBeGWbRgH4mBYA-1; Mon, 21 Aug 2023 05:47:02 -0400 X-MC-Unique: toGBDc-7NBeGWbRgH4mBYA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 183EB8030A9; Mon, 21 Aug 2023 09:47:02 +0000 (UTC) Received: from localhost (unknown [10.42.28.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F8AC40C2073; Mon, 21 Aug 2023 09:47:01 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Iain Sandoe Subject: [committed] libstdc++: Remove reliance on unspecified behaviour in std::rethrow_if_nested test Date: Mon, 21 Aug 2023 10:46:11 +0100 Message-ID: <20230821094701.1548195-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is the patch resolving the non-portable test that Iain raised in: https://gcc.gnu.org/pipermail/libstdc++/2023-August/056534.html Tested x86_64-linux. Pushed to trunk. Backports would be OK, but I don't think they are needed. -- >8 -- 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. --- .../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 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) -- 2.41.0