From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id B6702388881B; Mon, 10 Jan 2022 19:59:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6702388881B MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6424] c++: "more constrained" vs staticness of memfn [PR103783] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 54fa7daefe35cacf4a933947d1802318da193c01 X-Git-Newrev: 3e95a974c39e922d19bf7ac1246730c516ae01f2 Message-Id: <20220110195900.B6702388881B@sourceware.org> Date: Mon, 10 Jan 2022 19:59:00 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jan 2022 19:59:00 -0000 https://gcc.gnu.org/g:3e95a974c39e922d19bf7ac1246730c516ae01f2 commit r12-6424-g3e95a974c39e922d19bf7ac1246730c516ae01f2 Author: Patrick Palka Date: Mon Jan 10 14:57:51 2022 -0500 c++: "more constrained" vs staticness of memfn [PR103783] Here we're rejecting the calls to g1 and g2 as ambiguous even though one overload is more constrained than the other (and they're otherwise tied), because the implicit 'this' parameter of the non-static overload causes cand_parms_match to think the function parameter lists aren't equivalent. This patch fixes this by making cand_parms_match skip over 'this' appropriately. Note that this bug only affects partial ordering of non-template member functions because for member function templates more_specialized_fn seems to already skip over 'this' appropriately. PR c++/103783 gcc/cp/ChangeLog: * call.c (cand_parms_match): Skip over 'this' when given one static and one non-static member function. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-memfun2.C: New test. Diff: --- gcc/cp/call.c | 17 ++++++++++++++--- gcc/testsuite/g++.dg/cpp2a/concepts-memfun2.C | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 44fc6d0f695..88ab23392d2 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -11945,7 +11945,7 @@ joust_maybe_elide_copy (z_candidate *&cand) /* True if the defining declarations of the two candidates have equivalent parameters. */ -bool +static bool cand_parms_match (z_candidate *c1, z_candidate *c2) { tree fn1 = c1->fn; @@ -11967,8 +11967,19 @@ cand_parms_match (z_candidate *c1, z_candidate *c2) fn1 = DECL_TEMPLATE_RESULT (t1); fn2 = DECL_TEMPLATE_RESULT (t2); } - return compparms (TYPE_ARG_TYPES (TREE_TYPE (fn1)), - TYPE_ARG_TYPES (TREE_TYPE (fn2))); + tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1)); + tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2)); + if (DECL_FUNCTION_MEMBER_P (fn1) + && DECL_FUNCTION_MEMBER_P (fn2) + && (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn1) + != DECL_NONSTATIC_MEMBER_FUNCTION_P (fn2))) + { + /* Ignore 'this' when comparing the parameters of a static member + function with those of a non-static one. */ + parms1 = skip_artificial_parms_for (fn1, parms1); + parms2 = skip_artificial_parms_for (fn2, parms2); + } + return compparms (parms1, parms2); } /* Compare two candidates for overloading as described in diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun2.C new file mode 100644 index 00000000000..e3845e48387 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun2.C @@ -0,0 +1,25 @@ +// PR c++/103783 +// { dg-do compile { target c++20 } } + +template +struct A { + template void f1() = delete; + template static void f1() requires B; + + template void f2() requires B; + template static void f2() = delete; + + void g1() = delete; + static void g1() requires B; + + void g2() requires B; + static void g2() = delete; +}; + +int main() { + A a; + a.f1(); // OK + a.f2(); // OK + a.g1(); // OK, previously rejected as ambiguous + a.g2(); // OK, previously rejected as ambiguous +}