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

* [Bug c++/95849] Universal forwarding constructor inheritance resolution issue
  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 ` herring at lanl dot gov
  2021-09-01 18:37 ` [Bug c++/95849] [DR2356] " mpolacek at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: herring at lanl dot gov @ 2021-08-28 23:03 UTC (permalink / raw)
  To: gcc-bugs

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

S. Davis Herring <herring at lanl dot gov> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |herring at lanl dot gov

--- Comment #1 from S. Davis Herring <herring at lanl dot gov> ---
This is CWG2356
<http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2356>; GCC (along
with Clang) is correct.

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

* [Bug c++/95849] [DR2356] Universal forwarding constructor inheritance resolution issue
  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 ` mpolacek at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-09-01 18:37 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WORKSFORME
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks Davis.  Closing.

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