decl.c (warn_extern_redeclared_static): Check DECL_ARTIFICIAL...
authorJason Merrill <jason@yorick.cygnus.com>
Wed, 21 Jul 1999 08:52:14 +0000 (08:52 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 21 Jul 1999 08:52:14 +0000 (04:52 -0400)
* decl.c (warn_extern_redeclared_static): Check DECL_ARTIFICIAL,
not DECL_BUILT_IN, to determine if a function is internally declared.
(duplicate_decls): Likewise.  Improve handling of builtins.
(push_overloaded_decl): Remove special handling of builtins.

* cp-tree.h (ANON_AGGR_TYPE_P): Use CLASS_TYPE_P.

* decl.c (grokdeclarator): Pull out decl_constant_value in
templates, too.

* class.c (finish_struct, finish_struct_1): Remove 'warn_anon' parm.
* cp-tree.h, pt.c, semantics.c: Adjust.
* method.c (largest_union_member): Remove.

From-SVN: r28204

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/method.c
gcc/cp/pt.c
gcc/cp/semantics.c

index ca7a16685a477758f8355db5a031db1d85d2903f..7df7bab8e3368c424df62eee3d288d799cb85711 100644 (file)
@@ -1,5 +1,19 @@
 1999-07-20  Jason Merrill  <jason@yorick.cygnus.com>
 
+       * decl.c (warn_extern_redeclared_static): Check DECL_ARTIFICIAL,
+       not DECL_BUILT_IN, to determine if a function is internally declared.
+       (duplicate_decls): Likewise.  Improve handling of builtins.
+       (push_overloaded_decl): Remove special handling of builtins.
+
+       * cp-tree.h (ANON_AGGR_TYPE_P): Use CLASS_TYPE_P.
+
+       * decl.c (grokdeclarator): Pull out decl_constant_value in
+       templates, too.
+
+       * class.c (finish_struct, finish_struct_1): Remove 'warn_anon' parm.
+       * cp-tree.h, pt.c, semantics.c: Adjust.
+       * method.c (largest_union_member): Remove.
+
        * lang-specs.h (c++-cpp-output): Pass -fpreprocessed.
 
        * lex.c (token_getch, token_put_back): New fns.
index 6a25b5915ed8dfde9f1f70a65e0e666063d89fc1..41f1d79a914410d1b9cfd1059e46ea94dc78e992 100644 (file)
@@ -3202,9 +3202,8 @@ add_fields_to_vec (fields, field_vec, idx)
    ATTRIBUTES is the set of decl attributes to be applied, if any.  */
 
 void
-finish_struct_1 (t, warn_anon)
+finish_struct_1 (t)
      tree t;
-     int warn_anon;
 {
   int old;
   enum tree_code code = TREE_CODE (t);
@@ -4279,9 +4278,8 @@ unreverse_member_declarations (t)
 }
 
 tree
-finish_struct (t, attributes, warn_anon)
+finish_struct (t, attributes)
      tree t, attributes;
-     int warn_anon;
 {
   /* Append the fields we need for constructing signature tables.  */
   if (IS_SIGNATURE (t))
@@ -4299,7 +4297,7 @@ finish_struct (t, attributes, warn_anon)
       TYPE_SIZE (t) = integer_zero_node;
     }
   else
-    finish_struct_1 (t, warn_anon);
+    finish_struct_1 (t);
 
   TYPE_BEING_DEFINED (t) = 0;
 
index 07c952314866b5d1937fbbe3713f2952a90aad1b..55c93ea68b578fe27ffaeb73d935ab069c765a1c 100644 (file)
@@ -1848,8 +1848,7 @@ extern int flag_new_for_scope;
    flag for this because "A union for which objects or pointers are
    declared is not an anonymous union" [class.union].  */
 #define ANON_AGGR_TYPE_P(NODE)                         \
-  (TYPE_LANG_SPECIFIC (NODE)                           \
-   && TYPE_LANG_SPECIFIC (NODE)->type_flags.anon_aggr)
+  (CLASS_TYPE_P (NODE) && TYPE_LANG_SPECIFIC (NODE)->type_flags.anon_aggr)
 #define SET_ANON_AGGR_TYPE_P(NODE)                     \
   (TYPE_LANG_SPECIFIC (NODE)->type_flags.anon_aggr = 1)
 
@@ -2763,8 +2762,8 @@ extern void add_method                            PROTO((tree, tree *, tree));
 extern int currently_open_class                        PROTO((tree));
 extern tree get_vfield_offset                  PROTO((tree));
 extern void duplicate_tag_error                        PROTO((tree));
-extern tree finish_struct                      PROTO((tree, tree, int));
-extern void finish_struct_1                    PROTO((tree, int));
+extern tree finish_struct                      PROTO((tree, tree));
+extern void finish_struct_1                    PROTO((tree));
 extern int resolves_to_fixed_type_p            PROTO((tree, int *));
 extern void init_class_processing              PROTO((void));
 extern int is_empty_class                      PROTO((tree));
index 83237373b9c5265491797fcae6a3b28371a1c6f8..dda66fed65dc68a6a421d86fd9935afebc83de9b 100644 (file)
@@ -3048,8 +3048,7 @@ warn_extern_redeclared_static (newdecl, olddecl)
       if (! (TREE_CODE (newdecl) == FUNCTION_DECL
             && olddecl != NULL_TREE
             && TREE_CODE (olddecl) == FUNCTION_DECL
-            && (DECL_BUILT_IN (olddecl)
-                || DECL_BUILT_IN_NONANSI (olddecl))))
+            && DECL_ARTIFICIAL (olddecl)))
        {
          cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name)
                      ? implicit_extern_static_warning
@@ -3092,44 +3091,58 @@ duplicate_decls (newdecl, olddecl)
  
   /* Check for redeclaration and other discrepancies. */
   if (TREE_CODE (olddecl) == FUNCTION_DECL
-      && DECL_ARTIFICIAL (olddecl)
-      && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
-    {
-      /* If you declare a built-in or predefined function name as static,
-        the old definition is overridden, but optionally warn this was a
-        bad choice of name.  Ditto for overloads.  */
-      if (! TREE_PUBLIC (newdecl)
-         || (TREE_CODE (newdecl) == FUNCTION_DECL
-             && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
-       {
-         if (warn_shadow)
-           cp_warning ("shadowing %s function `%#D'",
-                       DECL_BUILT_IN (olddecl) ? "built-in" : "library",
+      && DECL_ARTIFICIAL (olddecl))
+    {
+      if (TREE_CODE (newdecl) != FUNCTION_DECL)
+       {
+         /* If you declare a built-in or predefined function name as static,
+            the old definition is overridden, but optionally warn this was a
+            bad choice of name.  */
+         if (! TREE_PUBLIC (newdecl))
+           {
+             if (warn_shadow)
+               cp_warning ("shadowing %s function `%#D'",
+                           DECL_BUILT_IN (olddecl) ? "built-in" : "library",
+                           olddecl);
+             /* Discard the old built-in function.  */
+             return 0;
+           }
+         /* If the built-in is not ansi, then programs can override
+            it even globally without an error.  */
+         else if (! DECL_BUILT_IN (olddecl))
+           cp_warning ("library function `%#D' redeclared as non-function `%#D'",
+                       olddecl, newdecl);
+         else
+           {
+             cp_error ("declaration of `%#D'", newdecl);
+             cp_error ("conflicts with built-in declaration `%#D'",
                        olddecl);
-         /* Discard the old built-in function.  */
+           }
          return 0;
        }
-      else if (! types_match)
+      else if (!types_match)
        {
-         if (TREE_CODE (newdecl) != FUNCTION_DECL)
+         if ((DECL_LANGUAGE (newdecl) == lang_c
+              && DECL_LANGUAGE (olddecl) == lang_c)
+             || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
+                           TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
            {
-             /* If the built-in is not ansi, then programs can override
-                it even globally without an error.  */
-             if (! DECL_BUILT_IN (olddecl))
-               cp_warning ("library function `%#D' redeclared as non-function `%#D'",
-                           olddecl, newdecl);
-             else
+             /* A near match; override the builtin.  */
+
+             if (TREE_PUBLIC (newdecl))
                {
-                 cp_error ("declaration of `%#D'", newdecl);
-                 cp_error ("conflicts with built-in declaration `%#D'",
-                           olddecl);
+                 cp_warning ("new declaration `%#D'", newdecl);
+                 cp_warning ("ambiguates built-in declaration `%#D'",
+                             olddecl);
                }
-             return 0;
+             else if (warn_shadow)
+               cp_warning ("shadowing %s function `%#D'",
+                           DECL_BUILT_IN (olddecl) ? "built-in" : "library",
+                           olddecl);
            }
-
-         cp_warning ("declaration of `%#D'", newdecl);
-         cp_warning ("conflicts with built-in declaration `%#D'",
-                     olddecl);
+         else
+           /* Discard the old built-in function.  */
+           return 0;
        }
     }
   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
@@ -4469,17 +4482,7 @@ push_overloaded_decl (decl, flags)
   int doing_global = (namespace_bindings_p () || !(flags & PUSH_LOCAL));
 
   if (doing_global)
-    {
-      old = namespace_binding (name, DECL_CONTEXT (decl));
-      if (old && TREE_CODE (old) == FUNCTION_DECL
-         && DECL_ARTIFICIAL (old)
-         && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old)))
-       {
-         if (duplicate_decls (decl, old))
-           return old;
-         old = NULL_TREE;
-       }
-    }
+    old = namespace_binding (name, DECL_CONTEXT (decl));
   else
     old = lookup_name_current_level (name);
 
@@ -10013,6 +10016,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
                if (TREE_CODE (size) == NOP_EXPR
                    && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
                  size = TREE_OPERAND (size, 0);
+               if (TREE_READONLY_DECL_P (size))
+                 size = decl_constant_value (size);
 
                /* If this involves a template parameter, it will be a
                   constant at instantiation time, but we don't know
@@ -10048,8 +10053,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
                              dname);
                    size = integer_one_node;
                  }
-               if (TREE_READONLY_DECL_P (size))
-                 size = decl_constant_value (size);
                if (pedantic && integer_zerop (size))
                  cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
                if (TREE_CONSTANT (size))
index caa3eb597a2ca08d740f1f279997a505a79cedc7..04f7b39ff3a4387ba075b7a8a4a2019b119e597b 100644 (file)
@@ -2180,24 +2180,6 @@ emit_thunk (thunk_fndecl)
 \f
 /* Code for synthesizing methods which have default semantics defined.  */
 
-/* For the anonymous union in TYPE, return the member that is at least as
-   large as the rest of the members, so we can copy it.  */
-
-static tree
-largest_union_member (type)
-     tree type;
-{
-  tree f, type_size = TYPE_SIZE (type);
-
-  for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
-    if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
-      return f;
-
-  /* We should always find one.  */
-  my_friendly_abort (323);
-  return NULL_TREE;
-}
-
 /* Generate code for default X(X&) constructor.  */
 
 static void
index bb48cc83203ce6bd2fa8b106e87d2bd1abd1419e..0744812cfc752932f9436ae1fdbabd018379bb24 100644 (file)
@@ -5183,7 +5183,7 @@ instantiate_class_template (type)
   input_filename = DECL_SOURCE_FILE (typedecl);
 
   unreverse_member_declarations (type);
-  finish_struct_1 (type, 0);
+  finish_struct_1 (type);
   CLASSTYPE_GOT_SEMICOLON (type) = 1;
 
   /* Clear this now so repo_template_used is happy.  */
index 059375b5e270163dd79994193e9102691d571f25..b66efdfebc7f58f5fcb3a7499280a0f0a880a90f 100644 (file)
@@ -1320,7 +1320,6 @@ begin_class_definition (t)
   /* Don't change signatures.  */
   if (! IS_SIGNATURE (t))
     {
-      int needs_writing;
       tree name = TYPE_IDENTIFIER (t);
       
       if (! ANON_AGGRNAME_P (name))
@@ -1464,7 +1463,7 @@ finish_class_definition (t, attributes, semi, pop_scope_p)
     ;
   else
     {
-      t = finish_struct (t, attributes, semi);
+      t = finish_struct (t, attributes);
       if (semi) 
        note_got_semicolon (t);
     }