public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope.
@ 2013-06-05 12:08 asaelr at gmail dot com
  2013-06-05 12:13 ` [Bug c++/57533] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: asaelr at gmail dot com @ 2013-06-05 12:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

            Bug ID: 57533
           Summary: When throwing local variable, it's being
                    move-constructed even if not going out of scope.
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: asaelr at gmail dot com

Created attachment 30260
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30260&action=edit
example file. (compile with -std=c++0x, and look at the string s)

When throwing variable, a copy of it is actually being throwed.
In c++0x, The compiler may optimize it to move (instead of copy), if this
variable is local, and is going out of scope (for example, if it's not in a try
block, the function will end).
However, gcc 4.7.3 does this optimization even if the variable is not going out
of scope.
As a result, the variable becomes invalid.


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

* [Bug c++/57533] When throwing local variable, it's being move-constructed even if not going out of scope.
  2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
@ 2013-06-05 12:13 ` redi at gcc dot gnu.org
  2013-06-05 12:17 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2013-06-05 12:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-06-05
     Ever confirmed|0                           |1
      Known to fail|                            |4.7.3, 4.8.1, 4.9.0

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced to remove library dependencies:

struct X
{
    bool moved = false;

    X() = default;
    X(const X&) = default;
    X(X&& x) { x.moved = true; }
};

int main()
{
    X x;
    try {
        throw x;
    }
    catch(...) {
    }
    if (x.moved)
        __builtin_abort();
}


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

* [Bug c++/57533] When throwing local variable, it's being move-constructed even if not going out of scope.
  2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
  2013-06-05 12:13 ` [Bug c++/57533] " redi at gcc dot gnu.org
@ 2013-06-05 12:17 ` paolo.carlini at oracle dot com
  2013-10-05 12:25 ` dmitriy-hshg at mail dot ru
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-05 12:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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

* [Bug c++/57533] When throwing local variable, it's being move-constructed even if not going out of scope.
  2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
  2013-06-05 12:13 ` [Bug c++/57533] " redi at gcc dot gnu.org
  2013-06-05 12:17 ` paolo.carlini at oracle dot com
@ 2013-10-05 12:25 ` dmitriy-hshg at mail dot ru
  2014-08-23 23:32 ` ville.voutilainen at gmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dmitriy-hshg at mail dot ru @ 2013-10-05 12:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

Dmitry <dmitriy-hshg at mail dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitriy-hshg at mail dot ru

--- Comment #2 from Dmitry <dmitriy-hshg at mail dot ru> ---
*** Bug 58629 has been marked as a duplicate of this bug. ***


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

* [Bug c++/57533] When throwing local variable, it's being move-constructed even if not going out of scope.
  2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
                   ` (2 preceding siblings ...)
  2013-10-05 12:25 ` dmitriy-hshg at mail dot ru
@ 2014-08-23 23:32 ` ville.voutilainen at gmail dot com
  2015-04-12 21:08 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ville.voutilainen at gmail dot com @ 2014-08-23 23:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

Ville Voutilainen <ville.voutilainen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tsimpson at ubuntu dot com

--- Comment #3 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
*** Bug 62172 has been marked as a duplicate of this bug. ***


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

* [Bug c++/57533] When throwing local variable, it's being move-constructed even if not going out of scope.
  2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
                   ` (3 preceding siblings ...)
  2014-08-23 23:32 ` ville.voutilainen at gmail dot com
@ 2015-04-12 21:08 ` redi at gcc dot gnu.org
  2021-02-04 10:39 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2015-04-12 21:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |frankhb1989 at gmail dot com

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 65748 has been marked as a duplicate of this bug. ***


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

* [Bug c++/57533] When throwing local variable, it's being move-constructed even if not going out of scope.
  2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
                   ` (4 preceding siblings ...)
  2015-04-12 21:08 ` redi at gcc dot gnu.org
@ 2021-02-04 10:39 ` redi at gcc dot gnu.org
  2021-02-04 10:55 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-02-04 10:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |njormrod at fb dot com

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 98938 has been marked as a duplicate of this bug. ***

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

* [Bug c++/57533] When throwing local variable, it's being move-constructed even if not going out of scope.
  2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
                   ` (5 preceding siblings ...)
  2021-02-04 10:39 ` redi at gcc dot gnu.org
@ 2021-02-04 10:55 ` redi at gcc dot gnu.org
  2021-02-04 10:59 ` redi at gcc dot gnu.org
  2021-12-17 11:25 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-02-04 10:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Seems to be fixed on trunk since

commit 1722e2013f05f1f1f99379dbaa0c0df356da731f
Author: Jason Merrill
Date:   Tue Jul 21 05:19:49 2020

    c++: Implement C++20 implicit move changes. [PR91427]

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

* [Bug c++/57533] When throwing local variable, it's being move-constructed even if not going out of scope.
  2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
                   ` (6 preceding siblings ...)
  2021-02-04 10:55 ` redi at gcc dot gnu.org
@ 2021-02-04 10:59 ` redi at gcc dot gnu.org
  2021-12-17 11:25 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-02-04 10:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Most of that commit only affects C++20 mode, but it includes:

            * typeck.c (treat_lvalue_as_rvalue_p): Overhaul.

The new treat_lvalue_as_rvalue_p code says:

+  /* if the operand of a throw-expression is a (possibly parenthesized)
+     id-expression that names an implicitly movable entity whose scope does
not
+     extend beyond the compound-statement of the innermost try-block or
+     function-try-block (if any) whose compound-statement or ctor-initializer
+     encloses the throw-expression, */

The "whose scope does not extend" part is what was missing before.

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

* [Bug c++/57533] When throwing local variable, it's being move-constructed even if not going out of scope.
  2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
                   ` (7 preceding siblings ...)
  2021-02-04 10:59 ` redi at gcc dot gnu.org
@ 2021-12-17 11:25 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17 11:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57533

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |11.1.0
      Known to fail|                            |10.3.0

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think we should just add the testcase and be done with it.

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

end of thread, other threads:[~2021-12-17 11:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-05 12:08 [Bug c++/57533] New: When throwing local variable, it's being move-constructed even if not going out of scope asaelr at gmail dot com
2013-06-05 12:13 ` [Bug c++/57533] " redi at gcc dot gnu.org
2013-06-05 12:17 ` paolo.carlini at oracle dot com
2013-10-05 12:25 ` dmitriy-hshg at mail dot ru
2014-08-23 23:32 ` ville.voutilainen at gmail dot com
2015-04-12 21:08 ` redi at gcc dot gnu.org
2021-02-04 10:39 ` redi at gcc dot gnu.org
2021-02-04 10:55 ` redi at gcc dot gnu.org
2021-02-04 10:59 ` redi at gcc dot gnu.org
2021-12-17 11:25 ` pinskia at gcc dot gnu.org

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).