diff --git a/gcc/cp/class.c b/gcc/cp/class.c index ca492cdbd40..c818826a108 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1081,12 +1081,19 @@ add_method (tree type, tree method, bool via_using) { 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); - if (sfk == sfk_none || DECL_INHERITED_CTOR (fn)) - /* Non-special member functions coexist if they are not - equivalently constrained. A member function is not hidden - by an inherited constructor. */ + if (sfk == sfk_none + || DECL_INHERITED_CTOR (fn) + || TREE_CODE (fn) == TEMPLATE_DECL) + /* 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; /* P0848: For special member functions, deleted, unsatisfied, or diff --git a/gcc/testsuite/g++.dg/concepts/pr95181-2.C b/gcc/testsuite/g++.dg/concepts/pr95181-2.C new file mode 100644 index 00000000000..6d67350e58f --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/pr95181-2.C @@ -0,0 +1,8 @@ +// { dg-do compile { target concepts } } + +template struct g { + g() requires B && false; + g() requires B; +}; + +g b; // error diff --git a/gcc/testsuite/g++.dg/concepts/pr95181.C b/gcc/testsuite/g++.dg/concepts/pr95181.C new file mode 100644 index 00000000000..0185c86b438 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/pr95181.C @@ -0,0 +1,9 @@ +// PR c++/95181 +// { dg-do compile { target concepts } } + +template struct f { + template f(); + template requires false f(); +}; + +f a;