From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1698) id BBB973860017; Tue, 23 Jun 2020 19:11:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBB973860017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592939494; bh=EH/mgYoBANWAhM8s4c4/SIqNenHYRB4OoF21PzEJipU=; h=From:To:Subject:Date:From; b=XzfQrAN2BWNsPM7TV/b5mU/95kJ81MulntOtHvJVyrPwL0uiBZ40C3Nl2+aac+D5M 6ytLcIw/pQemUmQ8ZvtzjtDFT9hvS6kAPyU7rxiiGw2xhUitQmjjtwh74YEaEXqYNf +Q9IuFMAYWMQjlOYzy9iqwK/Mp0M1qa1hCpYkGy0= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Iain D Sandoe To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/c++-coroutines] c++: Refinements to "more constrained". X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/devel/c++-coroutines X-Git-Oldrev: 3345e74299687de6144b87c0632018cafd4ccf3b X-Git-Newrev: 57b4daf8dc4ed7b669cc70638866ddb00f5b7746 Message-Id: <20200623191134.BBB973860017@sourceware.org> Date: Tue, 23 Jun 2020 19:11:34 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2020 19:11:34 -0000 https://gcc.gnu.org/g:57b4daf8dc4ed7b669cc70638866ddb00f5b7746 commit 57b4daf8dc4ed7b669cc70638866ddb00f5b7746 Author: Jason Merrill Date: Thu Jun 11 23:58:54 2020 -0400 c++: Refinements to "more constrained". P2113 from the last C++ meeting clarified that we only compare constraints on functions or function templates that have equivalent template parameters and function parameters. I'm not currently implementing the complicated handling of reversed comparison operators here; thinking about it now, it seems like a lot of complexity to support a very weird usage. If I write two similar comparison operators to be distinguished by their constraints, why would I write one reversed? If they're two unrelated operators, they're very unlikely to be similar enough for the complexity to help. I've started a discussion on the committee reflector about changing these rules. This change breaks some greedy_ops tests in libstdc++ that were relying on comparing constraints on unrelated templates, which seems pretty clearly wrong, so I'm removing those tests for now. gcc/cp/ChangeLog: * call.c (joust): Only compare constraints for non-template candidates with matching parameters. * pt.c (tsubst_pack_expansion): Fix getting a type parameter pack. (more_specialized_fn): Only compare constraints for candidates with matching parameters. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-return-req1.C: Expect error. * g++.dg/cpp2a/concepts-p2113a.C: New test. * g++.dg/cpp2a/concepts-p2113b.C: New test. libstdc++-v3/ChangeLog: * testsuite/24_iterators/move_iterator/rel_ops_c++20.cc: Remove greedy_ops tests. * testsuite/24_iterators/reverse_iterator/rel_ops_c++20.cc: Remove greedy_ops tests. Diff: --- gcc/cp/call.c | 11 +++++----- gcc/cp/pt.c | 14 +++++++++++- gcc/testsuite/g++.dg/cpp2a/concepts-p2113a.C | 12 +++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-p2113b.C | 25 ++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-return-req1.C | 2 +- .../24_iterators/move_iterator/rel_ops_c++20.cc | 19 ---------------- .../24_iterators/reverse_iterator/rel_ops_c++20.cc | 22 ------------------- 7 files changed, 57 insertions(+), 48 deletions(-) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 5382b7620dc..2b39a3700fc 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -11435,12 +11435,13 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn, return winner; } - /* Concepts: ... or, if not that, F1 is more constrained than F2. + /* Concepts: F1 and F2 are non-template functions with the same + parameter-type-lists, and F1 is more constrained than F2 according to the + partial ordering of constraints described in 13.5.4. */ - FIXME: For function templates with no winner, this subsumption may - be computed a separate time. This needs to be validated, and if - so, the redundant check removed. */ - if (flag_concepts && DECL_P (cand1->fn) && DECL_P (cand2->fn)) + if (flag_concepts && DECL_P (cand1->fn) && DECL_P (cand2->fn) + && !cand1->template_decl && !cand2->template_decl + && cand_parms_match (cand1, cand2)) { winner = more_constrained (cand1->fn, cand2->fn); if (winner) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1c0759edcae..efaadf73772 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -12849,6 +12849,10 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain, template_parm_level_and_index (parm_pack, &level, &idx); if (level <= levels) arg_pack = TMPL_ARG (args, level, idx); + + if (arg_pack && TREE_CODE (arg_pack) == TEMPLATE_TYPE_PARM + && TEMPLATE_TYPE_PARAMETER_PACK (arg_pack)) + arg_pack = NULL_TREE; } orig_arg = arg_pack; @@ -24061,7 +24065,15 @@ more_specialized_fn (tree pat1, tree pat2, int len) /* If both deductions succeed, the partial ordering selects the more constrained template. */ - if (!lose1 && !lose2) + /* P2113: If the corresponding template-parameters of the + template-parameter-lists are not equivalent ([temp.over.link]) or if + the function parameters that positionally correspond between the two + templates are not of the same type, neither template is more + specialized than the other. */ + if (!lose1 && !lose2 + && comp_template_parms (DECL_TEMPLATE_PARMS (pat1), + DECL_TEMPLATE_PARMS (pat2)) + && compparms (origs1, origs2)) { int winner = more_constrained (decl1, decl2); if (winner > 0) diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-p2113a.C b/gcc/testsuite/g++.dg/cpp2a/concepts-p2113a.C new file mode 100644 index 00000000000..e2652dd12f3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-p2113a.C @@ -0,0 +1,12 @@ +// Test that the second foo is not considered more specialized because we don't +// compare constraints unless the template parameters and function parameters +// are equivalent (P2113) + +// { dg-do compile { target c++20 } } + +template concept P = true; + +template void foo(int, T); +template

void foo(U, int); + +void bar() { foo(1,2); } // { dg-error "ambiguous" } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-p2113b.C b/gcc/testsuite/g++.dg/cpp2a/concepts-p2113b.C new file mode 100644 index 00000000000..18c4098d473 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-p2113b.C @@ -0,0 +1,25 @@ +// testcase from P2113 +// { dg-do compile { target c++20 } } + +template constexpr bool True = true; +template concept C = True; + +void f(C auto &, auto &) = delete; +template void f(Q &, C auto &); + +void g(struct A *ap, struct B *bp) { + f(*ap, *bp); // OK: Can use different methods to produce template parameters +} + +template struct X {}; + +template +bool operator==(X, V1) = delete; + +// In P2113 this candidate is reversed. +template +bool operator==(X, V2); + +void h() { + X{} == 0; // OK +} diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-return-req1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-return-req1.C index 84c9ae9d6da..d21a49be14e 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-return-req1.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-return-req1.C @@ -15,5 +15,5 @@ int f(...); int main() { - f(); + f(); // { dg-error "ambiguous" } } diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc index a530923f8ad..b298a312aae 100644 --- a/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc @@ -142,22 +142,3 @@ static_assert( cend > beg ); static_assert( beg <= cend ); static_assert( cend >= beg ); static_assert( std::is_lt(beg <=> cend) ); - -#include - -void test01() -{ - typedef std::move_iterator iterator_type; - - iterator_type it(nullptr); - - it == it; - it != it; - it < it; - it <= it; - it > it; - it >= it; - // it - it; // See PR libstdc++/71771 - 1 + it; - it + 1; -} diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/rel_ops_c++20.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/rel_ops_c++20.cc index a382ae52483..e513efba57f 100644 --- a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/rel_ops_c++20.cc +++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/rel_ops_c++20.cc @@ -169,25 +169,3 @@ static_assert( crend > rbeg ); static_assert( rbeg <= crend ); static_assert( crend >= rbeg ); static_assert( std::is_lt(rbeg <=> crend) ); - -#include - -// copied from 24_iterators/reverse_iterator/greedy_ops.cc -void test01() -{ - typedef std::reverse_iterator iterator_type; - - iterator_type it; - - it == it; - it != it; - it < it; - it <= it; - it > it; - it >= it; -#if __cplusplus < 201103L - it - it; // See PR libstdc++/71771 -#endif - 1 + it; - it + 1; -}