From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2C95F38768A2; Fri, 17 Nov 2023 00:21:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C95F38768A2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700180500; bh=kupgEMTXJEsADcY++yf60Ej8kf3yn1q51F8hMV1jg38=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IRPlBtRQYQuEoDcKZnZoy1O9qQ2Gq+ff34o9mwffSF3Lq6+gDPnT7C3NsGEVD2FST +BOE+RHaknXQsm6uLLNEmU5ejLnJ0SPuio6jd/gVqEK8QFeCGeJah8nPvrGi6py4xN zRmMpSgzksiMrcXvaKwTkwYK3LozHTbY+Q5SUTkc= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws Date: Fri, 17 Nov 2023 00:21:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jason at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D33799 --- Comment #27 from CVS Commits --- The releases/gcc-13 branch has been updated by Jason Merrill : https://gcc.gnu.org/g:d237e7b291ff52095d600e6489a54b4ba8aaf608 commit r13-8079-gd237e7b291ff52095d600e6489a54b4ba8aaf608 Author: Jason Merrill Date: Mon Oct 30 17:44:54 2023 -0400 c++: retval dtor on rethrow [PR112301] In r12-6333 for PR33799, I fixed the example in [except.ctor]/2. In th= at testcase, the exception is caught and the function returns again, successfully. In this testcase, however, the exception is rethrown, and hits two sepa= rate cleanups: one in the try block and the other in the function body. So = we destroy twice an object that was only constructed once. Fortunately, the fix for the normal case is easy: we just need to clear= the "return value constructed by return" flag when we do it the first time. This gets more complicated with the named return value optimization, si= nce we don't want to destroy the return value while the NRV variable is sti= ll in scope. PR c++/112301 PR c++/102191 PR c++/33799 gcc/cp/ChangeLog: * except.cc (maybe_splice_retval_cleanup): Clear current_retval_sentinel when destroying retval. * semantics.cc (nrv_data): Add in_nrv_cleanup. (finalize_nrv): Set it. (finalize_nrv_r): Fix handling of throwing cleanups. gcc/testsuite/ChangeLog: * g++.dg/eh/return1.C: Add more cases.=