From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 23EE23857354; Wed, 7 Jun 2023 01:33:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23EE23857354 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686101623; bh=W4ytZPCCbVYWnP1yz0WPx/HJzlIqRJbHOc31BPh+lZI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=f1/UwikV8whiWxYOG+GzNfcuErOd4MbuofehnaWC84w5jZI/Qh4nA/PSD5IVoi1V8 wpsodnTqgeQX+8tKBRuowg0hlE5DC4Gi5yrQ8wwe2hirbjzzvrl3Ww+OMMqB/Ttux2 l5ISMTS7veen7KWXbvAnSG4BG+RT/VcLYDDHKT/8= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/92407] Destruction of objects returned from functions skipped by goto Date: Wed, 07 Jun 2023 01:33:41 +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: 9.2.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jason at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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=3D92407 --- Comment #8 from CVS Commits --- The trunk branch has been updated by Jason Merrill : https://gcc.gnu.org/g:7e0b65b239c3a0d68ce94896b236b03de666ffd6 commit r14-1593-g7e0b65b239c3a0d68ce94896b236b03de666ffd6 Author: Jason Merrill Date: Sun Jun 4 12:09:11 2023 -0400 c++: enable NRVO from inner block [PR51571] Our implementation of the named return value optimization has been limi= ted to variables declared in the outermost block of the function, to avoid needing to handle the case where the variable needs to be destroyed due= to going out of scope. PR92407 pointed out a case we were missing, where = the variable goes out of scope due to a goto and we were failing to destroy= it. It occurred to me that this problem is the flip side of PR33799, where = we need to be sure to destroy the return value if a cleanup throws on retu= rn; here we want to avoid destroying the return value when exiting the variable's scope on return. We can use the same flag to indicate to bo= th cleanups that we're returning. This implements the guaranteed copy elision specified by P2025 (which is not yet part of the draft standard). PR c++/51571 PR c++/92407 gcc/cp/ChangeLog: * decl.cc (finish_function): Simplify NRV handling. * except.cc (maybe_set_retval_sentinel): Also set if NRV. (maybe_splice_retval_cleanup): Don't add the cleanup region if we don't need it. * semantics.cc (nrv_data): Add simple field. (finalize_nrv): Set it. (finalize_nrv_r): Check it and retval sentinel. * cp-tree.h (finalize_nrv): Adjust declaration. * typeck.cc (check_return_expr): Remove named_labels check. gcc/testsuite/ChangeLog: * g++.dg/opt/nrv23.C: New test.=