This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/62172] New: Operand to a throw expression is moved when it should be copied


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]