]> gcc.gnu.org Git - gcc.git/commitdiff
c++: variable partial spec redeclaration [PR113612]
authorJason Merrill <jason@redhat.com>
Tue, 13 Feb 2024 02:00:53 +0000 (21:00 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 13 Feb 2024 16:16:29 +0000 (11:16 -0500)
If register_specialization finds a previous declaration and throws the new
one away, we shouldn't still add the new one to
DECL_TEMPLATE_SPECIALIZATIONS.

PR c++/113612

gcc/cp/ChangeLog:

* pt.cc (process_partial_specialization): Return early
on redeclaration.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/var-templ85.C: New test.

(cherry picked from commit 19ac327de421fe05916e234e3450e6e1cc5c935c)

gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp1y/var-templ85.C [new file with mode: 0644]

index 98974ba57549895e1aa241dcf900eec03359cf39..f5e6541fd0f029ce65b4b92b022df899880a8cd7 100644 (file)
@@ -5409,9 +5409,14 @@ process_partial_specialization (tree decl)
     }
 
   if (VAR_P (decl))
-    /* We didn't register this in check_explicit_specialization so we could
-       wait until the constraints were set.  */
-    decl = register_specialization (decl, maintmpl, specargs, false, 0);
+    {
+      /* We didn't register this in check_explicit_specialization so we could
+        wait until the constraints were set.  */
+      tree reg = register_specialization (decl, maintmpl, specargs, false, 0);
+      if (reg != decl)
+       /* Redeclaration.  */
+       return reg;
+    }
   else
     associate_classtype_constraints (type);
 
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ85.C b/gcc/testsuite/g++.dg/cpp1y/var-templ85.C
new file mode 100644 (file)
index 0000000..33c24e0
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/113612
+// { dg-do compile { target c++14 } }
+
+template <typename T> T t;
+template <typename T> extern T *t<T *>;
+template <typename T> T *t<T *> = t<int>;
This page took 0.093114 seconds and 5 git commands to generate.