From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AFE0B395C000; Tue, 23 Jun 2020 21:13:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFE0B395C000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592946796; bh=q3ZzviZAUG04rVfruhwmtJFvT+AJ0Z9dTk0GpgHCh/0=; h=From:To:Subject:Date:From; b=yFaUmf9xIUXZroJWV4JSCSGms4ydBpJ4XMLFZKdYpn+HdQhjq6u05uYTnSM6yXBNm Vxh7Y/Px7v6326feq+md/siCBYoqDxi2Cw9GI0BaNtkYAL2agAjGa6NoqF0SYIrlq0 Q/tpSYCXi+aUNLdFWUHp4yR8wzqd0MS6ngLtz0fw= From: "njormrod at fb dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95849] New: Universal forwarding constructor inheritance resolution issue Date: Tue, 23 Jun 2020 21:13:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: njormrod at fb dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2020 21:13:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95849 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 ma= tch 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 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 corre= ct behavior.=