c++: concepts TS and explicit specialization [PR101098]

duplicate_decls was not recognizing the explicit specialization as matching
the implicit specialization of g<Y> because
function_requirements_equivalent_p was seeing the C constraint on the
implicit one and not on the explicit.

	PR c++/101098

gcc/cp/ChangeLog:

	* decl.c (function_requirements_equivalent_p): Only compare
	trailing requirements on a specialization.

gcc/testsuite/ChangeLog:

	* g++.dg/concepts/explicit-spec1.C: New test.
This commit is contained in:
Jason Merrill 2021-07-09 13:50:01 -04:00
parent d5b1bb0d19
commit ddd25bd1a7
2 changed files with 12 additions and 1 deletions

View File

@ -955,7 +955,9 @@ static bool
function_requirements_equivalent_p (tree newfn, tree oldfn)
{
/* In the concepts TS, the combined constraints are compared. */
if (cxx_dialect < cxx20)
if (cxx_dialect < cxx20
&& (DECL_TEMPLATE_SPECIALIZATION (newfn)
<= DECL_TEMPLATE_SPECIALIZATION (oldfn)))
{
tree ci1 = get_constraints (oldfn);
tree ci2 = get_constraints (newfn);

View File

@ -0,0 +1,9 @@
// PR c++/101098
// { dg-do compile { target concepts } }
template<typename T> concept C = __is_class(T);
struct Y { int n; } y;
template<C T> void g(T) { }
int called;
template<> void g(Y) { called = 3; }
int main() { g(y); }