re PR c++/14428 (incompatible template declarations accepted)
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
Wed, 25 Aug 2004 14:56:10 +0000 (14:56 +0000)
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>
Wed, 25 Aug 2004 14:56:10 +0000 (14:56 +0000)
PR c++/14428
* pt.c (redeclare_class_template): Check the type of non-type and
template template parameter.

* g++.dg/template/redecl2.C: New test.

From-SVN: r86550

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/redecl2.C [new file with mode: 0644]

index fcb04047c64f07477502015a98d625b565e17994..5655232343a64df6391a8795878c63fc1c999e41 100644 (file)
@@ -1,3 +1,9 @@
+2004-08-25  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/14428
+       * pt.c (redeclare_class_template): Check the type of non-type and
+       template template parameter.
+
 2004-08-25  Nathan Sidwell  <nathan@codesourcery.com>
 
 
index b995ba41daae70ebef2d607ff40fad028a81ee9f..b93599eaf508f184220e34f8b3cca701370a7253 100644 (file)
@@ -3157,7 +3157,11 @@ redeclare_class_template (tree type, tree parms)
       tree tmpl_default = TREE_PURPOSE (TREE_VEC_ELT (tmpl_parms, i));
       tree parm_default = TREE_PURPOSE (TREE_VEC_ELT (parms, i));
 
-      if (TREE_CODE (tmpl_parm) != TREE_CODE (parm))
+      /* TMPL_PARM and PARM can be either TYPE_DECL, PARM_DECL, or
+        TEMPLATE_DECL.  */
+      if (TREE_CODE (tmpl_parm) != TREE_CODE (parm)
+         || (TREE_CODE (tmpl_parm) != TYPE_DECL
+             && !same_type_p (TREE_TYPE (tmpl_parm), TREE_TYPE (parm))))
        {
          cp_error_at ("template parameter `%#D'", tmpl_parm);
          error ("redeclared here as `%#D'", parm);
index 9a442c429404c1ea2fbc7549ab6c56ea6f272089..4647822b2617aa923211d734bccc6b9232e83551 100644 (file)
@@ -1,3 +1,8 @@
+2004-08-25  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/14428
+       * g++.dg/template/redecl2.C: New test.
+
 2004-08-24  Bud Davis  <bdavis9659@comcast.net>
 
        PR fortran/17143
diff --git a/gcc/testsuite/g++.dg/template/redecl2.C b/gcc/testsuite/g++.dg/template/redecl2.C
new file mode 100644 (file)
index 0000000..4dd432e
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-do compile }
+
+// Origin: heinlein@informatik.uni-ulm.de
+
+// PR c++/14428: Redeclaration of class template with wrong
+// non-type template parameter.
+
+template <int i> struct X;     // { dg-error "template parameter" }
+template <int* p> struct X;    // { dg-error "redeclared here" }