]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/92576 - redeclaration of variable template.
authorJason Merrill <jason@redhat.com>
Tue, 17 Dec 2019 21:46:11 +0000 (16:46 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 17 Dec 2019 21:46:11 +0000 (16:46 -0500)
The variable templates patch way back when forgot to add handling here.  The
simplest answer seems to be recursing to the underlying declaration.

* decl.c (redeclaration_error_message): Recurse for variable
templates.

From-SVN: r279472

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp1y/var-templ32.C
gcc/testsuite/g++.dg/cpp1y/var-templ65.C [new file with mode: 0644]

index e8a94f463e5bb8db82400443d89c42e680829390..e5824d57cc009cc50986a77854a6622138056f6d 100644 (file)
@@ -1,3 +1,9 @@
+2019-12-17  Jason Merrill  <jason@redhat.com>
+
+       PR c++/92576 - redeclaration of variable template.
+       * decl.c (redeclaration_error_message): Recurse for variable
+       templates.
+
 2019-12-17  Jason Merrill  <jason@redhat.com>
 
        * name-lookup.c (get_std_name_hint): Add std::byte.
index 6dec5838303faab3052b02a4ad843e97b501beb5..86717dc8fed108c3c546a9b563d30d07568f582f 100644 (file)
@@ -2977,20 +2977,14 @@ redeclaration_error_message (tree newdecl, tree olddecl)
     {
       tree nt, ot;
 
-      if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
-       {
-         if (COMPLETE_TYPE_P (TREE_TYPE (newdecl))
-             && COMPLETE_TYPE_P (TREE_TYPE (olddecl)))
-           return G_("redefinition of %q#D");
-         return NULL;
-       }
-
       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
         return G_("redefinition of %q#D");
 
-      if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL
-         || (DECL_TEMPLATE_RESULT (newdecl)
-             == DECL_TEMPLATE_RESULT (olddecl)))
+      if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
+       return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
+                                           DECL_TEMPLATE_RESULT (olddecl));
+
+      if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
        return NULL;
 
       nt = DECL_TEMPLATE_RESULT (newdecl);
index 80077a16b56679f67d7b267c83d2839d493bd06b..6767ff1d9c69a3738039f662272d0759574f340d 100644 (file)
@@ -4,4 +4,4 @@ template<typename T>
 bool V1 = true;
 
 template<typename T>
-bool V1<int> = false; // { dg-error "primary template|not deducible" }
+bool V1<int> = false; // { dg-error "primary template|redefinition|not deducible" }
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ65.C b/gcc/testsuite/g++.dg/cpp1y/var-templ65.C
new file mode 100644 (file)
index 0000000..10398bb
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/84255
+// { dg-do compile { target c++14 } }
+
+template<typename T> constexpr int var;
+template<typename T> constexpr int var = 1; // { dg-error "redefinition" }