]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: concepts TS and explicit specialization [PR101098]
authorJason Merrill <jason@redhat.com>
Fri, 9 Jul 2021 17:50:01 +0000 (13:50 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 9 Jul 2021 20:14:14 +0000 (16:14 -0400)
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.

gcc/cp/decl.c
gcc/testsuite/g++.dg/concepts/explicit-spec1.C [new file with mode: 0644]

index 9cfe62a98eeb47bf5b2acabeced44a63886a0ec9..5e101ffb8437c9d4780d8134d688fc7e08148471 100644 (file)
@@ -944,7 +944,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);
diff --git a/gcc/testsuite/g++.dg/concepts/explicit-spec1.C b/gcc/testsuite/g++.dg/concepts/explicit-spec1.C
new file mode 100644 (file)
index 0000000..d9b6b3d
--- /dev/null
@@ -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); }