public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/62172] New: Operand to a throw expression is moved when it should be copied
@ 2014-08-18 15:34 tsimpson at ubuntu dot com
  2014-08-18 16:02 ` [Bug c++/62172] " ville.voutilainen at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: tsimpson at ubuntu dot com @ 2014-08-18 15:34 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-08-23 23:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-18 15:34 [Bug c++/62172] New: Operand to a throw expression is moved when it should be copied tsimpson at ubuntu dot com
2014-08-18 16:02 ` [Bug c++/62172] " ville.voutilainen at gmail dot com
2014-08-23 23:28 ` redi at gcc dot gnu.org
2014-08-23 23:32 ` ville.voutilainen at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).