public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tsimpson at ubuntu dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-62172-4@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2014-08-18 15:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-18 15:34 tsimpson at ubuntu dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-62172-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).