decl.c (tag_name): New fn.

* decl.c (tag_name): New fn.
	(xref_tag): Complain about using typedef-name after class-key.
Fixes Sec7/1_3/C07351.cm.
	* init.c (expand_vec_init): Also keep going if from_array.
Fixes g++.other/copy1.C.
	* tree.c (is_overloaded_fn): Also handle the output of
	build_offset_ref.
Fixes Sec5/3_3/S05162.C.
	* decl.c (grokdeclarator): Use constructor_name when comparing
	field name against enclosing class.
	* class.c (finish_struct_anon): Likewise.
Fixes Sec9/2/C09268.cm.

From-SVN: r23758
This commit is contained in:
Jason Merrill 1998-11-22 21:34:27 +00:00 committed by Jason Merrill
parent 8190f0737f
commit 094fe153c4
5 changed files with 61 additions and 9 deletions

View File

@ -1,3 +1,17 @@
1998-11-22 Jason Merrill <jason@yorick.cygnus.com>
* decl.c (tag_name): New fn.
(xref_tag): Complain about using typedef-name after class-key.
* init.c (expand_vec_init): Also keep going if from_array.
* tree.c (is_overloaded_fn): Also handle the output of
build_offset_ref.
* decl.c (grokdeclarator): Use constructor_name when comparing
field name against enclosing class.
* class.c (finish_struct_anon): Likewise.
1998-11-22 Mark Mitchell <mark@markmitchell.com> 1998-11-22 Mark Mitchell <mark@markmitchell.com>
* decl.c (poplevel): Remove code to handle KEEP == 2. * decl.c (poplevel): Remove code to handle KEEP == 2.

View File

@ -3143,7 +3143,7 @@ finish_struct_anon (t)
if (DECL_ARTIFICIAL (*uelt)) if (DECL_ARTIFICIAL (*uelt))
continue; continue;
if (DECL_NAME (*uelt) == TYPE_IDENTIFIER (t)) if (DECL_NAME (*uelt) == constructor_name (t))
cp_pedwarn_at ("ANSI C++ forbids member `%D' with same name as enclosing class", cp_pedwarn_at ("ANSI C++ forbids member `%D' with same name as enclosing class",
*uelt); *uelt);

View File

@ -10299,7 +10299,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
if (decl_context == FIELD) if (decl_context == FIELD)
{ {
if (declarator == current_class_name) if (declarator == constructor_name (current_class_type))
cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class", cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class",
declarator); declarator);
decl = build_lang_decl (TYPE_DECL, declarator, type); decl = build_lang_decl (TYPE_DECL, declarator, type);
@ -10781,7 +10781,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
} }
/* 9.2p13 [class.mem] */ /* 9.2p13 [class.mem] */
if (declarator == current_class_name) if (declarator == constructor_name (current_class_type))
cp_pedwarn ("ANSI C++ forbids data member `%D' with same name as enclosing class", cp_pedwarn ("ANSI C++ forbids data member `%D' with same name as enclosing class",
declarator); declarator);
@ -11703,6 +11703,27 @@ grok_op_properties (decl, virtualp, friendp)
} }
} }
static char *
tag_name (code)
enum tag_types code;
{
switch (code)
{
case record_type:
return "struct";
case class_type:
return "class";
case union_type:
return "union ";
case enum_type:
return "enum";
case signature_type:
return "signature";
default:
my_friendly_abort (981122);
}
}
/* Get the struct, enum or union (CODE says which) with tag NAME. /* Get the struct, enum or union (CODE says which) with tag NAME.
Define the tag as a forward-reference if it is not defined. Define the tag as a forward-reference if it is not defined.
@ -11817,7 +11838,12 @@ xref_tag (code_type_node, name, globalize)
else else
{ {
if (t) if (t)
ref = t; {
if (t != TYPE_MAIN_VARIANT (t))
cp_pedwarn ("using typedef-name `%D' after `%s'",
TYPE_NAME (t), tag_name (tag_code));
ref = t;
}
else else
ref = lookup_tag (code, name, b, 0); ref = lookup_tag (code, name, b, 0);

View File

@ -2798,6 +2798,8 @@ expand_vec_init (decl, base, maxindex, init, from_array)
tree elts; tree elts;
tree baseref = build1 (INDIRECT_REF, type, base); tree baseref = build1 (INDIRECT_REF, type, base);
from_array = 0;
for (elts = CONSTRUCTOR_ELTS (init); elts; elts = TREE_CHAIN (elts)) for (elts = CONSTRUCTOR_ELTS (init); elts; elts = TREE_CHAIN (elts))
{ {
tree elt = TREE_VALUE (elts); tree elt = TREE_VALUE (elts);
@ -2853,10 +2855,14 @@ expand_vec_init (decl, base, maxindex, init, from_array)
/* Now, default-initialize any remaining elements. We don't need to /* Now, default-initialize any remaining elements. We don't need to
do that if a) the type does not need constructing, or b) we've do that if a) the type does not need constructing, or b) we've
already initialized all the elements. */ already initialized all the elements.
if (TYPE_NEEDS_CONSTRUCTING (type)
&& !(TREE_CODE (maxindex) == INTEGER_CST We do need to keep going if we're copying an array. */
&& num_initialized_elts == TREE_INT_CST_LOW (maxindex) + 1))
if (from_array
|| (TYPE_NEEDS_CONSTRUCTING (type)
&& !(TREE_CODE (maxindex) == INTEGER_CST
&& num_initialized_elts == TREE_INT_CST_LOW (maxindex) + 1)))
{ {
/* If the ITERATOR is equal to -1, then we don't have to loop; /* If the ITERATOR is equal to -1, then we don't have to loop;
we've already initialized all the elements. */ we've already initialized all the elements. */

View File

@ -1294,9 +1294,15 @@ is_overloaded_fn (x)
tree x; tree x;
{ {
/* XXX A baselink is also considered an overloaded function. /* XXX A baselink is also considered an overloaded function.
As is a placeholder from push_class_decls. */ As is a placeholder from push_class_decls.
As is an expression like X::f. */
if (TREE_CODE (x) == TREE_LIST) if (TREE_CODE (x) == TREE_LIST)
{ {
if (TREE_PURPOSE (x) == error_mark_node)
{
x = TREE_VALUE (x);
my_friendly_assert (TREE_CODE (x) == TREE_LIST, 981121);
}
my_friendly_assert (TREE_CODE (TREE_PURPOSE (x)) == TREE_VEC my_friendly_assert (TREE_CODE (TREE_PURPOSE (x)) == TREE_VEC
|| TREE_CODE (TREE_PURPOSE (x)) == IDENTIFIER_NODE, || TREE_CODE (TREE_PURPOSE (x)) == IDENTIFIER_NODE,
388); 388);