]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
decl.c (grokdeclarator): Allow field with same name as class in extern "C".
authorJason Merrill <jason@yorick.cygnus.com>
Sat, 12 Dec 1998 16:41:15 +0000 (16:41 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 12 Dec 1998 16:41:15 +0000 (11:41 -0500)
* 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
gcc/cp/class.c
gcc/cp/decl.c
gcc/cp/lex.c

index fa24faee8d32b05f73de6f6642b8245874bc2a61..1c3bd37b8412da5c1dc21b16226952f551cec236 100644 (file)
@@ -1,3 +1,13 @@
+1998-12-08  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * 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  <mark@markmitchell.com>
 
        * decl.c (start_enum): Use push_obstacks, not
index 46d162e50870a6ba0c1c4b9aa58547079d6a596f..a73605a96e5df9b7a834119343580eeb2a09a069 100644 (file)
@@ -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.  */
index c278875d8c71fe6145e22392cce1b9d0e432901c..c2afcb7d0fcfdf913507de9198421b2982e9e899 100644 (file)
@@ -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);
 
index 4c118715706970c52c10e5532f7873ae3689bb7b..45d3d41c3c9e42850ec9edf67cb7694ed0ffbf07 100644 (file)
@@ -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;
        }