From 4d7614e9f1741e6d01c35ba1e40e22da4abe91cd Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sat, 12 Dec 1998 16:41:15 +0000 Subject: [PATCH] decl.c (grokdeclarator): Allow field with same name as class in extern "C". * decl.c (grokdeclarator): Allow field with same name as class in extern "C". * decl.c (lookup_name_real): Don't limit field lookup to types. * class.c (check_member_decl_is_same_in_complete_scope): No error if icv and x are the same. * lex.c (do_identifier): Tweak error message. From-SVN: r24269 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/class.c | 4 +++- gcc/cp/decl.c | 13 +++++++++---- gcc/cp/lex.c | 3 +-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fa24faee8d3..1c3bd37b841 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +1998-12-08 Jason Merrill + + * decl.c (grokdeclarator): Allow field with same name as class + in extern "C". + + * decl.c (lookup_name_real): Don't limit field lookup to types. + * class.c (check_member_decl_is_same_in_complete_scope): No error + if icv and x are the same. + * lex.c (do_identifier): Tweak error message. + 1998-12-10 Mark Mitchell * decl.c (start_enum): Use push_obstacks, not diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 46d162e5087..a73605a96e5 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -4371,7 +4371,9 @@ check_member_decl_is_same_in_complete_scope (t, x) else icv = NULL_TREE; - if (icv + /* This should match pushdecl_class_level. */ + if (icv && icv != x + && flag_optional_diags /* Don't complain about constructors. */ && name != constructor_name (current_class_type) /* Or inherited names. */ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index c278875d8c7..c2afcb7d0fc 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3809,6 +3809,7 @@ pushdecl_class_level (x) members are checked in finish_struct. */ tree icv = IDENTIFIER_CLASS_VALUE (name); + /* This should match check_member_decl_is_same_in_complete_scope. */ if (icv && icv != x && flag_optional_diags /* Don't complain about inherited names. */ @@ -5191,9 +5192,9 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) classval = IDENTIFIER_CLASS_VALUE (name); if (classval == NULL_TREE && TYPE_BEING_DEFINED (current_class_type)) /* Try to find values from base classes if we are presently - defining a type. We are presently only interested in - TYPE_DECLs. */ - classval = lookup_field (current_class_type, name, 0, 1); + defining a type. We are primarily interested in + TYPE_DECLs or constants. */ + classval = lookup_field (current_class_type, name, 0, prefer_type); /* Add implicit 'typename' to types from template bases. lookup_field will do this for us. If classval is actually from an enclosing @@ -10824,7 +10825,11 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) } /* 9.2p13 [class.mem] */ - if (declarator == constructor_name (current_class_type)) + if (declarator == constructor_name (current_class_type) + /* Divergence from the standard: In extern "C", we + allow non-static data members here, because C does + and /usr/include/netinet/in.h uses that. */ + && (staticp || current_lang_name != lang_c)) cp_pedwarn ("ANSI C++ forbids data member `%D' with same name as enclosing class", declarator); diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 4c118715706..45d3d41c3c9 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -2934,8 +2934,7 @@ do_identifier (token, parsing, args) my_friendly_abort (61); else { - cp_error ("invalid use of member `%D' from base class `%T'", field, - DECL_FIELD_CONTEXT (field)); + cp_error ("invalid use of member `%D'", field); id = error_mark_node; return id; }