public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95849] New: Universal forwarding constructor inheritance resolution issue
@ 2020-06-23 21:13 njormrod at fb dot com
  2021-08-28 23:03 ` [Bug c++/95849] " herring at lanl dot gov
  2021-09-01 18:37 ` [Bug c++/95849] [DR2356] " mpolacek at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: njormrod at fb dot com @ 2020-06-23 21:13 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2021-09-01 18:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 21:13 [Bug c++/95849] New: Universal forwarding constructor inheritance resolution issue njormrod at fb dot com
2021-08-28 23:03 ` [Bug c++/95849] " herring at lanl dot gov
2021-09-01 18:37 ` [Bug c++/95849] [DR2356] " mpolacek 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).