public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98938] New: throw calls move constructor
@ 2021-02-02 18:47 njormrod at fb dot com
  2021-02-04 10:39 ` [Bug c++/98938] " redi at gcc dot gnu.org
  2021-02-04 10:55 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: njormrod at fb dot com @ 2021-02-02 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98938
           Summary: throw calls move constructor
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: njormrod at fb dot com
  Target Milestone: ---

Throwing invokes the move constructor instead of the copy constructor.

Demonstration of move-constructor in godbolt: https://gcc.godbolt.org/z/zhjv5z
Demonstration of copy-constructor using clang: https://gcc.godbolt.org/z/E3MEef

>From 14.2 Throwing an exception [except.throw]: "Throwing an exception
copy-initializes (9.4, 11.4.5.3) a temporary object, called the exception
object."

Code (as used in godbolt):

```
#include <exception>

struct A : std::exception {
    A(int* q) : p(q) {}
    A(const A& a) : p(a.p) { *p = 12345; }
    A(A&& a) : p(a.p) { *p = 56789; }

    int* p;
};

int foo() {
    int i = 10;
    A a(&i);
    try {
        throw a;
    } catch (A&) {}
    return i;
}
```

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

* [Bug c++/98938] throw calls move constructor
  2021-02-02 18:47 [Bug c++/98938] New: throw calls move constructor njormrod at fb dot com
@ 2021-02-04 10:39 ` redi at gcc dot gnu.org
  2021-02-04 10:55 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ 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=98938

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
.

*** This bug has been marked as a duplicate of bug 57533 ***

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

* [Bug c++/98938] throw calls move constructor
  2021-02-02 18:47 [Bug c++/98938] New: throw calls move constructor njormrod at fb dot com
  2021-02-04 10:39 ` [Bug c++/98938] " redi at gcc dot gnu.org
@ 2021-02-04 10:55 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ 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=98938

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
With GCC trunk there's a copy, 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] 3+ messages in thread

end of thread, other threads:[~2021-02-04 10:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 18:47 [Bug c++/98938] New: throw calls move constructor njormrod at fb dot com
2021-02-04 10:39 ` [Bug c++/98938] " redi at gcc dot gnu.org
2021-02-04 10:55 ` redi 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).