From 2649701fbb53874b7564d0c30f0b3dbe26ffb819 Mon Sep 17 00:00:00 2001 From: Kriang Lerdsuwanakij Date: Wed, 25 Aug 2004 14:56:10 +0000 Subject: [PATCH] re PR c++/14428 (incompatible template declarations accepted) 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 | 6 ++++++ gcc/cp/pt.c | 6 +++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/redecl2.C | 9 +++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/redecl2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fcb04047c64..5655232343a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-08-25 Kriang Lerdsuwanakij + + PR c++/14428 + * pt.c (redeclare_class_template): Check the type of non-type and + template template parameter. + 2004-08-25 Nathan Sidwell diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b995ba41daa..b93599eaf50 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9a442c42940..4647822b261 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-08-25 Kriang Lerdsuwanakij + + PR c++/14428 + * g++.dg/template/redecl2.C: New test. + 2004-08-24 Bud Davis 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 index 00000000000..4dd432e6fea --- /dev/null +++ b/gcc/testsuite/g++.dg/template/redecl2.C @@ -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 struct X; // { dg-error "template parameter" } +template struct X; // { dg-error "redeclared here" } -- 2.30.2