From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7CBF938582B7; Wed, 13 Jul 2022 12:30:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CBF938582B7 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106281] New: Order failed overload candidates so ones with wrong number of params and inaccessible ones come last Date: Wed, 13 Jul 2022 12:30:42 +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: unknown X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org 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 keywords 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: Wed, 13 Jul 2022 12:30:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106281 Bug ID: 106281 Summary: Order failed overload candidates so ones with wrong number of params and inaccessible ones come last Product: gcc Version: unknown Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- template class C { public: C() =3D default; template C(AA, BB) { } C(C&&) =3D default; private: struct __secret_tag { }; template C(AA&, BB&, __secret_tag) { } }; C c({}, {}); We get these errors: cons.C:20:21: error: no matching function for call to =E2=80=98C::C(, )=E2=80=99 20 | C c({}, {}); | ^ cons.C:16:5: note: candidate: =E2=80=98template C= ::C(AA&, BB&, __secret_tag) [with BB =3D AA; A =3D int; B =3D int]=E2=80=99 16 | C(AA&, BB&, __secret_tag) | ^ cons.C:16:5: note: template argument deduction/substitution failed: cons.C:20:21: note: candidate expects 3 arguments, 2 provided 20 | C c({}, {}); | ^ cons.C:8:5: note: candidate: =E2=80=98template C:= :C(AA, BB) [with BB =3D AA; A =3D int; B =3D int]=E2=80=99 8 | C(AA, BB) | ^ cons.C:8:5: note: template argument deduction/substitution failed: cons.C:20:21: note: couldn=E2=80=99t deduce template parameter =E2=80=98A= A=E2=80=99 20 | C c({}, {}); | ^ cons.C:11:3: note: candidate: =E2=80=98constexpr C::C(C&&) [wit= h A =3D int; B =3D int]=E2=80=99 11 | C(C&&) =3D default; | ^ cons.C:11:3: note: candidate expects 1 argument, 2 provided cons.C:5:3: note: candidate: =E2=80=98constexpr C::C() [with A =3D in= t; B =3D int]=E2=80=99 5 | C() =3D default; | ^ cons.C:5:3: note: candidate expects 0 arguments, 2 provided The first candidate shown: - is private - requires 3 parameters and only 2 args were used - is the last one defined in the class What is the logic that makes that come first? A private constructor that takes a "secret" third parameter of a type that = is also private to the class is probably not what the user code was trying to = use! The second candidate is the one being called. It is public and has the right number of args. It should be shown first (although the "[with BB =3D AA;" is nonsense, it's claiming that the arg subsitituting the first param is the second param ... wat?). Clang shows a more useful order, although still not the order they're decla= red in the class, so it still seems arbitrary: cons.C:20:13: error: no matching constructor for initialization of 'C' C c({}, {}); ^ ~~~~~~ cons.C:8:5: note: candidate template ignored: couldn't infer template argum= ent 'AA' C(AA, BB) ^ cons.C:11:3: note: candidate constructor not viable: requires 1 argument, b= ut 2 were provided C(C&&) =3D default; ^ cons.C:2:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided class C ^ cons.C:16:5: note: candidate constructor template not viable: requires 3 arguments, but 2 were provided C(AA&, BB&, __secret_tag) ^ cons.C:5:3: note: candidate constructor not viable: requires 0 arguments, b= ut 2 were provided C() =3D default; ^=