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

            Bug ID: 105465
           Summary: С++14 behaviour of inherited constructors broken
           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: ---

In the following program struct B inherits A(Foo) constructor, which is called
from main:

#include <iostream>

struct Foo {
    Foo() {}
    Foo(const Foo&) { std::cout << "Foo(const Foo&)\n"; }
};

struct A {
    A(Foo) {}
};

struct B : A {
    using A::A;
};

int main() {
    Foo f;
    B b(f);
}

According to C++14 standard
(https://timsong-cpp.github.io/cppwp/n4140/class.inhctor#8) the compiler shall
produce
B::B(Foo f) : A(f) { }

so the call `B(f)` leads to 2 copies of Foo and the program shall print:
Foo(const Foo&)
Foo(const Foo&)

And indeed GCC 6.4 prints so. But starting from GCC 7 only one copy is made.
Demo: https://gcc.godbolt.org/z/sTqKzdj5v

Related discussion: https://stackoverflow.com/a/56241478/7325599

Is it a regression?

Reply via email to