cp-tree.h: Declare.

�
1998-08-24  Benjamin Kosnik  <bkoz@cygnus.com>
	* cp-tree.h: Declare.
	* pt.c (decl_template_parm_p): New function.
	* decl.c (pushdecl): Check decls for redeclaring template parms.
	(xref_tag): Make redeclaration an error, print decl.
	* decl2.c (grokfield): Check field_decls for redeclaration as well.

From-SVN: r21943
This commit is contained in:
Benjamin Kosnik 1998-08-24 11:57:09 +00:00
parent 22a7be5365
commit 2450bb7d4d
3 changed files with 28 additions and 3 deletions

View File

@ -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));

View File

@ -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;

View File

@ -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));