diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 26e39a95892..b73fb535484 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -2837,6 +2837,7 @@ extern int more_specialized_class PROTO((tree, tree)); extern void do_pushlevel PROTO((void)); extern int is_member_template PROTO((tree)); extern int comp_template_parms PROTO((tree, tree)); +extern int decl_template_parm_p PROTO((tree)); extern int template_class_depth PROTO((tree)); extern int is_specialization_of PROTO((tree, tree)); extern int comp_template_args PROTO((tree, tree)); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8c3a32bd2e9..f232fdd4d73 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3669,6 +3669,16 @@ pushdecl (x) if (warnstring) warning (warnstring, IDENTIFIER_POINTER (name)); } + /* Check to see if decl redeclares a template parameter. */ + if (oldlocal && (current_class_type || current_function_decl ) + && current_template_parms) + { + if (decl_template_parm_p (oldlocal)) + { + cp_error ("redeclaration of template parameter `%T'", name); + cp_error_at (" previously declared here `%#D'", oldlocal); + } + } } if (TREE_CODE (x) == FUNCTION_DECL) @@ -11480,11 +11490,12 @@ xref_tag (code_type_node, name, binfo, globalize) if (! globalize) { - if (pedantic && t && (TREE_CODE (t) == TEMPLATE_TYPE_PARM + if (t && (TREE_CODE (t) == TEMPLATE_TYPE_PARM || TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)) { - cp_pedwarn ("redeclaration of template type-parameter `%T'", name); - cp_pedwarn_at (" previously declared here", t); + cp_error ("redeclaration of template type-parameter `%T'", name); + cp_error_at (" previously declared here `%#D'", + TEMPLATE_TYPE_DECL (t)); } if (t && TYPE_CONTEXT (t) && got_type) ref = t; diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 9333d8dcf12..b8c4370ceb9 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1761,6 +1761,19 @@ grokfield (declarator, declspecs, init, asmspec_tree, attrlist) && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL)) value = push_template_decl (value); + /* Check to see if a field redeclares a template parameter. */ + if (current_template_parms + && TREE_CODE (declarator) == IDENTIFIER_NODE + && IDENTIFIER_LOCAL_VALUE (declarator)) + { + tree olddecl = IDENTIFIER_LOCAL_VALUE (declarator); + if (decl_template_parm_p (olddecl)) + { + cp_error ("redeclaration of template parameter `%T'", declarator); + cp_error_at (" previously declared here `%#D'", olddecl); + } + } + if (attrlist) cplus_decl_attributes (value, TREE_PURPOSE (attrlist), TREE_VALUE (attrlist));