Commit 9e81c820 by Patrick Palka Committed by Jason Merrill

c++: P0848R3 and member function templates [PR95181]

When comparing two special member function templates to see if one hides
the other (as per P0848R3), we need to check satisfaction which we can't
do on templates.  So this patch makes add_method skip the eligibility
test on member function templates and just lets them coexist.

gcc/cp/ChangeLog:

	PR c++/95181
	* class.c (add_method): Let special member function templates
	coexist if they are not equivalently constrained, or in a class
	template.

gcc/testsuite/ChangeLog:

	PR c++/95181
	* g++.dg/concepts/pr95181.C: New test.
	* g++.dg/concepts/pr95181-2.C: New test.

Co-authored-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 6b449b74c590f5a6f66c73aed894e5b5b36aa59d)
parent c07c745b
...@@ -1077,12 +1077,19 @@ add_method (tree type, tree method, bool via_using) ...@@ -1077,12 +1077,19 @@ add_method (tree type, tree method, bool via_using)
{ {
if (!equivalently_constrained (fn, method)) if (!equivalently_constrained (fn, method))
{ {
if (processing_template_decl)
/* We can't check satisfaction in dependent context, wait until
the class is instantiated. */
continue;
special_function_kind sfk = special_memfn_p (method); special_function_kind sfk = special_memfn_p (method);
if (sfk == sfk_none || DECL_INHERITED_CTOR (fn)) if (sfk == sfk_none
/* Non-special member functions coexist if they are not || DECL_INHERITED_CTOR (fn)
equivalently constrained. A member function is not hidden || TREE_CODE (fn) == TEMPLATE_DECL)
by an inherited constructor. */ /* Member function templates and non-special member functions
coexist if they are not equivalently constrained. A member
function is not hidden by an inherited constructor. */
continue; continue;
/* P0848: For special member functions, deleted, unsatisfied, or /* P0848: For special member functions, deleted, unsatisfied, or
......
// { dg-do compile { target concepts } }
template<bool B> struct g {
g() requires B && false;
g() requires B;
};
g<true> b; // error
// PR c++/95181
// { dg-do compile { target concepts } }
template <typename> struct f {
template <typename T=int> f();
template <typename T=int> requires false f();
};
f<int> a;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment