public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105465] New: С++14 behaviour of inherited constructors broken
@ 2022-05-03 10:18 fchelnokov at gmail dot com
  2022-05-03 17:07 ` [Bug c++/105465] " redi at gcc dot gnu.org
  2022-05-03 17:08 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: fchelnokov at gmail dot com @ 2022-05-03 10:18 UTC (permalink / raw)
  To: gcc-bugs

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?

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

* [Bug c++/105465] С++14 behaviour of inherited constructors broken
  2022-05-03 10:18 [Bug c++/105465] New: С++14 behaviour of inherited constructors broken fchelnokov at gmail dot com
@ 2022-05-03 17:07 ` redi at gcc dot gnu.org
  2022-05-03 17:08 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-03 17:07 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No it's not a regression, and it's not broken, it's correct.

https://wg21.link/P0136R1 changed the rules for C++17, resolving CWG1573,
CWG1645, CWG1715, CWG1736, CWG1903, CWG1941, CWG1959, and CWG1991 in the
process.

The old rule was inferior, nobody *wants* two copies of Foo there, that just
makes the program slower for no reason.

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

* [Bug c++/105465] С++14 behaviour of inherited constructors broken
  2022-05-03 10:18 [Bug c++/105465] New: С++14 behaviour of inherited constructors broken fchelnokov at gmail dot com
  2022-05-03 17:07 ` [Bug c++/105465] " redi at gcc dot gnu.org
@ 2022-05-03 17:08 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-03 17:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And this was already explained in the stackoverflow answer.

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

end of thread, other threads:[~2022-05-03 17:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-03 10:18 [Bug c++/105465] New: С++14 behaviour of inherited constructors broken fchelnokov at gmail dot com
2022-05-03 17:07 ` [Bug c++/105465] " redi at gcc dot gnu.org
2022-05-03 17:08 ` redi 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).