From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6AEC13858409; Wed, 13 Oct 2021 08:43:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AEC13858409 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102704] NRVO for throw expression Date: Wed, 13 Oct 2021 08:43:56 +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: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: everconfirmed bug_status cf_reconfirmed_on 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Oct 2021 08:43:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102704 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2021-10-13 --- Comment #2 from Jonathan Wakely --- [class.copy.elision] p1: This elision of copy/move operations, called copy elision, is permitted in = the following circumstances (which may be combined to eliminate multiple copies= ): -- in a return statement [...] -- in a throw-expression (7.6.18), when the operand is the name of a non-volatile object with automatic storage duration (other than a function = or catch-clause parameter) that belongs to a scope that does not contain the innermost enclosing compound-statement associated with a try-block (if ther= e is one), the copy/move operation can be omitted by constructing the object directly into the exception object -- in a coroutine [...] -- when the exception-declaration of an exception handler [...] The slightly confusing "does not contain the innermost enclosing compound-statement" means you can't elide if the throw is in a try-block and the variable was defined outside it. So this cannot be elided: void f() { mytype x; try { throw x; } catch (int) { } } But this can be: void g() { try { mytype x; throw x; } catch (int) { } } And the example in comment 0 can be.=