diff mbox series

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

Message ID 20210709201343.1604241-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: concepts TS and explicit specialization [PR101098] | expand

Commit Message

Jason Merrill July 9, 2021, 8:13 p.m. UTC
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.

I think that the usefulness of much of the concepts TS support is limited and
waning, but I guess we can keep it around for GCC 12.

Tested x86_64-pc-linux-gnu, applying to trunk and 11.

	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                                  | 4 +++-
 gcc/testsuite/g++.dg/concepts/explicit-spec1.C | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/concepts/explicit-spec1.C


base-commit: d5b1bb0d197f9141a0f0e510f8d1b598c3df9552
diff mbox series

Patch

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index ebe1318d38d..0df689b01f8 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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);
diff --git a/gcc/testsuite/g++.dg/concepts/explicit-spec1.C b/gcc/testsuite/g++.dg/concepts/explicit-spec1.C
new file mode 100644
index 00000000000..d9b6b3d1741
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/explicit-spec1.C
@@ -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); }