OSDN Git Service

2009-06-05 Alexander Strange <astrange@ithinksw.com>
[pf3gnuchains/gcc-fork.git] / gcc / c-decl.c
index a9929c1..2aa018f 100644 (file)
@@ -1114,6 +1114,27 @@ pushtag (tree name, tree type, location_t loc)
   /* An approximation for now, so we can tell this is a function-scope tag.
      This will be updated in pop_scope.  */
   TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
+
+  if (warn_cxx_compat && name != NULL_TREE)
+    {
+      struct c_binding *b = I_SYMBOL_BINDING (name);
+
+      if (b != NULL
+         && b->decl != NULL_TREE
+         && TREE_CODE (b->decl) == TYPE_DECL
+         && (B_IN_CURRENT_SCOPE (b)
+             || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
+         && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl))
+             != TYPE_MAIN_VARIANT (type)))
+       {
+         warning_at (loc, OPT_Wc___compat,
+                     ("using %qD as both a typedef and a tag is "
+                      "invalid in C++"),
+                     b->decl);
+         if (b->locus != UNKNOWN_LOCATION)
+           inform (b->locus, "originally defined here");
+       }
+    }
 }
 \f
 /* Subroutine of compare_decls.  Allow harmless mismatches in return
@@ -4181,6 +4202,7 @@ grokdeclarator (const struct c_declarator *declarator,
   bool bitfield = width != NULL;
   tree element_type;
   struct c_arg_info *arg_info = 0;
+  const char *errmsg;
   tree expr_dummy;
   bool expr_const_operands_dummy;
 
@@ -4814,6 +4836,12 @@ grokdeclarator (const struct c_declarator *declarator,
                  error ("type name declared as function returning an array");
                type = integer_type_node;
              }
+           errmsg = targetm.invalid_return_type (type);
+           if (errmsg)
+             {
+               error (errmsg);
+               type = integer_type_node;
+             }
 
            /* Construct the function type and go to the next
               inner layer of declarator.  */
@@ -4961,6 +4989,26 @@ grokdeclarator (const struct c_declarator *declarator,
        C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
       if (declspecs->inline_p)
        pedwarn (input_location, 0,"typedef %q+D declared %<inline%>", decl);
+
+      if (warn_cxx_compat && declarator->u.id != NULL_TREE)
+       {
+         struct c_binding *b = I_TAG_BINDING (declarator->u.id);
+
+         if (b != NULL
+             && b->decl != NULL_TREE
+             && (B_IN_CURRENT_SCOPE (b)
+                 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
+             && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type))
+           {
+             warning_at (declarator->id_loc, OPT_Wc___compat,
+                         ("using %qD as both a typedef and a tag is "
+                          "invalid in C++"),
+                         decl);
+             if (b->locus != UNKNOWN_LOCATION)
+               inform (b->locus, "originally defined here");
+           }
+       }
+
       return decl;
     }
 
@@ -5340,6 +5388,7 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
     {
       tree parm, type, typelt;
       unsigned int parmno;
+      const char *errmsg;
 
       /* If there is a parameter of incomplete type in a definition,
         this is an error.  In a declaration this is valid, and a
@@ -5383,6 +5432,14 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
                }
            }
 
+         errmsg = targetm.invalid_parameter_type (type);
+         if (errmsg)
+           {
+             error (errmsg);
+             TREE_VALUE (typelt) = error_mark_node;
+             TREE_TYPE (parm) = error_mark_node;
+           }
+
          if (DECL_NAME (parm) && TREE_USED (parm))
            warn_if_shadowing (parm);
        }