From 435a15bfc34326c87a5ca3bb53797b2011884311 Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 22 Nov 1998 21:34:27 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@23758 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 14 ++++++++++++++ gcc/cp/class.c | 2 +- gcc/cp/decl.c | 32 +++++++++++++++++++++++++++++--- gcc/cp/init.c | 14 ++++++++++---- gcc/cp/tree.c | 8 +++++++- 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 15b37aa..91d64dd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,17 @@ +1998-11-22 Jason Merrill + + * 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 * decl.c (poplevel): Remove code to handle KEEP == 2. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 6e89ce5..9ade201 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3143,7 +3143,7 @@ finish_struct_anon (t) if (DECL_ARTIFICIAL (*uelt)) 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", *uelt); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d50c5ea..b28b82c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10299,7 +10299,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) 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", declarator); decl = build_lang_decl (TYPE_DECL, declarator, type); @@ -10781,7 +10781,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) } /* 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", 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. Define the tag as a forward-reference if it is not defined. @@ -11817,7 +11838,12 @@ xref_tag (code_type_node, name, globalize) else { 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 ref = lookup_tag (code, name, b, 0); diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 76271b7..fd52814 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2798,6 +2798,8 @@ expand_vec_init (decl, base, maxindex, init, from_array) tree elts; tree baseref = build1 (INDIRECT_REF, type, base); + from_array = 0; + for (elts = CONSTRUCTOR_ELTS (init); elts; elts = TREE_CHAIN (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 do that if a) the type does not need constructing, or b) we've - already initialized all the elements. */ - if (TYPE_NEEDS_CONSTRUCTING (type) - && !(TREE_CODE (maxindex) == INTEGER_CST - && num_initialized_elts == TREE_INT_CST_LOW (maxindex) + 1)) + already initialized all the elements. + + We do need to keep going if we're copying an array. */ + + 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; we've already initialized all the elements. */ diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 8be0f98..2140189 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1294,9 +1294,15 @@ is_overloaded_fn (x) tree x; { /* 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_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 || TREE_CODE (TREE_PURPOSE (x)) == IDENTIFIER_NODE, 388); -- 2.7.4