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

            Bug ID: 95849
           Summary: Universal forwarding constructor inheritance
                    resolution issue
           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: ---

Universal forwarding constructors have a known oddity: they are a better match
than the copy constructor for non-const objects.

If a derived class inherits its parent's constructors, where the parent has a
universal forwarding constructor, then the derived class's default copy
constructor (having signature `const Derived&`) should likewise be usurped by
the non-const universal-forwarding constructor.

This is not the case in gcc.

Code demonstrating the bug: foo() and bar() should both return 8, but bar()
actually returns 7.

```
struct A {
    A(const A&) : x(7) {}

    template <typename U>
    A(U&&) : x(8) {}

    int x;
};

int foo() {
    A o1(true);
    A o2(o1);
    return o2.x;
}

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

int bar() {
    B o1(true);
    B o2(o1);
    return o2.x;
}
```


Godbolt link for gcc: https://gcc.godbolt.org/z/Y_sXD6. Bug is present.
Godbolt link for clang: https://gcc.godbolt.org/z/BFjYph. Bug is present.
Godbolt link for msvc: https://gcc.godbolt.org/z/GQ2z3x. msvc has the correct
behavior.

Reply via email to