public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96065] New: Move elision of returned automatic variable doesn't happen the variable is enclosed in a block
@ 2020-07-05  8:19 b7.10110111 at gmail dot com
  2020-07-05  9:44 ` [Bug c++/96065] " glisse at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: b7.10110111 at gmail dot com @ 2020-07-05  8:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96065
           Summary: Move elision of returned automatic variable doesn't
                    happen the variable is enclosed in a block
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: b7.10110111 at gmail dot com
  Target Milestone: ---

Consider the following code (at Godbolt's: https://gcc.godbolt.org/z/CyqPF9 ):

```
struct A
{
    A();
    A(A&&);
    A(A const&);
    A& operator=(A&&);
    A& operator=(A const&);
};

A getA()
{
    {
        A a;
        return a;
    }
}

int main()
{
    const A a=getA();
}
```

Here we get A::A() call followed by A::A(A&&) call. If we remove the inner
braces in getA(), move elision happens, so only A::A() is called. I'd expect
that without removal of braces move elision would also happen.

This problem of missing move elision also affects the case when the block
belongs to an if statement. Same pattern happens with copy elision if we
comment out the move constructor.

For comparison, MSVC 19.24 (with /O2 flag) and Clang 10.0 (by default) both
elide the move.

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

* [Bug c++/96065] Move elision of returned automatic variable doesn't happen the variable is enclosed in a block
  2020-07-05  8:19 [Bug c++/96065] New: Move elision of returned automatic variable doesn't happen the variable is enclosed in a block b7.10110111 at gmail dot com
@ 2020-07-05  9:44 ` glisse at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-07-05  9:44 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

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

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
dup

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

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

end of thread, other threads:[~2020-07-05  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-05  8:19 [Bug c++/96065] New: Move elision of returned automatic variable doesn't happen the variable is enclosed in a block b7.10110111 at gmail dot com
2020-07-05  9:44 ` [Bug c++/96065] " glisse 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).