public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization
@ 2022-01-29 13:10 fchelnokov at gmail dot com
  2022-01-29 17:11 ` [Bug c++/104282] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-29 13:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104282
           Summary: Copy elision when initializing a base-class subobject
                    with aggregate initialization
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The program
```
#include <iostream>

struct A {
  A() { std::cout << "A "; } 
  A(const A&) { std::cout << "Acopy "; } 
  A(A&&) { std::cout << "Amove "; } 
  ~A() { std::cout << "~A "; }
};

struct B : A { };

int main() {
    B b{ A{} };
}
```
if compiled by GCC, prints `A ~A `, showing that there is no copy/move of the
temporary `A{}`.
Clang prints on the other hand `A Amove ~A ~A `, which looks correct, because
of "no elision when initializing a base-class subobject", see
https://en.cppreference.com/w/cpp/language/copy_elision

Demo: https://gcc.godbolt.org/z/rafEsTdd9

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

end of thread, other threads:[~2024-03-22  7:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
2022-01-29 17:11 ` [Bug c++/104282] " pinskia at gcc dot gnu.org
2022-01-29 17:12 ` pinskia at gcc dot gnu.org
2022-01-29 17:15 ` fchelnokov at gmail dot com
2022-01-29 19:26 ` redi at gcc dot gnu.org
2022-01-29 19:29 ` redi at gcc dot gnu.org
2022-01-29 23:34 ` pinskia at gcc dot gnu.org
2023-01-16  4:23 ` pinskia at gcc dot gnu.org
2024-03-22  7:52 ` fchelnokov at gmail dot com

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