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

Reply via email to