From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24901 invoked by alias); 18 Aug 2014 15:34:03 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 24679 invoked by uid 48); 18 Aug 2014 15:33:56 -0000 From: "tsimpson at ubuntu dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/62172] New: Operand to a throw expression is moved when it should be copied Date: Mon, 18 Aug 2014 15:34:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: tsimpson at ubuntu dot com X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg01217.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62172 Bug ID: 62172 Summary: Operand to a throw expression is moved when it should be copied Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tsimpson at ubuntu dot com Created attachment 33352 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33352&action=edit test case With a throw expression whos operand is an lvalue, which is declared outside the try block, will move from the expression instead of copy. The relavent part of the standard is 15.1 [except.throw]. The C++11 standard *could* be interpreded to allow the move when reading the last sentence of 15.1/3 "...Except for these restrictions and the restrictions on type matching mentioned in 15.3, the operand of throw is treated exactly as a function argument in a call (5.2.2) or the operand of a return statement." Specifically, if the operand of the throw expression was treated exactly the same as an operand to a return statement then it would become an xvalue and the move would be allowed. The wording of that clause changed in C++14, so this is no longer the case. And I don't think it was the intent to allow that in C++11 either. Example output with g++ http://rextester.com/USFXJ5678 Exmaple output with clang++ http://rextester.com/EARQ18237