re PR c++/6321 (no warning for bad main function declaration)
authorDirk Mueller <dmueller@suse.de>
Mon, 30 Oct 2006 23:15:42 +0000 (23:15 +0000)
committerDirk Mueller <mueller@gcc.gnu.org>
Mon, 30 Oct 2006 23:15:42 +0000 (23:15 +0000)
2006-10-30  Dirk Mueller  <dmueller@suse.de>

        PR c++/6321
        * cp/decl.c (grokfndecl): Use check_main_parameter_types.

        * c-common.h (strict_aliasing_warning): Fix whitespace.
        * c-decl (start_function): Move code for main decl warning ..
        * c-common.c (check_main_parameter_types): .. here.
        * c-common.h (check_main_parameter_types): Declare.

From-SVN: r118206

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-decl.c
gcc/cp/ChangeLog
gcc/cp/decl.c

index 87126bd54e0c06903c589e3263426606f9599ab8..93ce3426685f2b96ab7d0e4054712a7feb7e48d3 100644 (file)
@@ -1,3 +1,10 @@
+2006-10-30  Dirk Mueller  <dmueller@suse.de>
+
+       * c-common.h (strict_aliasing_warning): Fix whitespace.
+       * c-decl (start_function): Move code for main decl warning ..
+       * c-common.c (check_main_parameter_types): .. here.
+       * c-common.h (check_main_parameter_types): Declare.
 2006-10-30  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        PR middle-end/29335
index e51de2d734161f63899e10d704a5491793caf074..a901aba2f50bca6f864eb2b49b8bf490c1838804 100644 (file)
@@ -1010,7 +1010,6 @@ strict_aliasing_warning (tree otype, tree type, tree expr)
     }
 }
 
-
 /* Print a warning about if (); or if () .. else; constructs
    via the special empty statement node that we create.  INNER_THEN
    and INNER_ELSE are the statement lists of the if and the else
@@ -1039,7 +1038,59 @@ empty_body_warning (tree inner_then, tree inner_else)
    }
 }
 
-  
+/* Warn for unlikely, improbable, or stupid DECL declarations
+   of `main'.  */
+
+void
+check_main_parameter_types (tree decl)
+{
+  tree args;
+  int argct = 0;
+
+  for (args = TYPE_ARG_TYPES (TREE_TYPE (decl)); args;
+      args = TREE_CHAIN (args))
+   {
+     tree type = args ? TREE_VALUE (args) : 0;
+
+     if (type == void_type_node)
+       break;
+
+     ++argct;
+     switch (argct)
+       {
+       case 1:
+         if (TYPE_MAIN_VARIANT (type) != integer_type_node)
+           pedwarn ("first argument of %q+D should be %<int%>", decl);
+         break;
+
+       case 2:
+         if (TREE_CODE (type) != POINTER_TYPE
+             || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
+             || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
+                 != char_type_node))
+           pedwarn ("second argument of %q+D should be %<char **%>",
+                    decl);
+         break;
+
+       case 3:
+         if (TREE_CODE (type) != POINTER_TYPE
+             || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
+             || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
+                 != char_type_node))
+           pedwarn ("third argument of %q+D should probably be "
+                    "%<char **%>", decl);
+         break;
+       }
+   }
+
+  /* It is intentional that this message does not mention the third
+    argument because it's only mentioned in an appendix of the
+    standard.  */
+  if (argct > 0 && (argct < 2 || argct > 3))
+   pedwarn ("%q+D takes only zero or two arguments", decl);
+}
+
 /* Nonzero if constant C has a value that is permissible
    for type TYPE (an INTEGER_TYPE).  */
 
index 633990a3a35bc47c409db4f81d135413f063bab1..f6f36e0114fa9e6ed0652ef0ba513a76bbc049a0 100644 (file)
@@ -654,10 +654,11 @@ extern void binary_op_error (enum tree_code);
 extern tree fix_string_type (tree);
 struct varray_head_tag;
 extern void constant_expression_warning (tree);
-extern void strict_aliasing_warning(tree, tree, tree);
+extern void strict_aliasing_warning (tree, tree, tree);
 extern void empty_body_warning (tree, tree);
 extern tree convert_and_check (tree, tree);
 extern void overflow_warning (tree);
+extern void check_main_parameter_types (tree decl);
 extern bool c_determine_visibility (tree);
 extern bool same_scalar_type_ignoring_signedness (tree, tree);
 
index e740fcac9172c128bc9ef1e77702739e0402aff1..7ebb8b9c4f10fa2eeb40aaa5249b65c678f1c9a5 100644 (file)
@@ -6133,54 +6133,11 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
   /* Warn for unlikely, improbable, or stupid declarations of `main'.  */
   if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1)))
     {
-      tree args;
-      int argct = 0;
-
       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
          != integer_type_node)
        pedwarn ("return type of %q+D is not %<int%>", decl1);
 
-      for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
-          args = TREE_CHAIN (args))
-       {
-         tree type = args ? TREE_VALUE (args) : 0;
-
-         if (type == void_type_node)
-           break;
-
-         ++argct;
-         switch (argct)
-           {
-           case 1:
-             if (TYPE_MAIN_VARIANT (type) != integer_type_node)
-               pedwarn ("first argument of %q+D should be %<int%>", decl1);
-             break;
-
-           case 2:
-             if (TREE_CODE (type) != POINTER_TYPE
-                 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
-                 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
-                     != char_type_node))
-               pedwarn ("second argument of %q+D should be %<char **%>",
-                        decl1);
-             break;
-
-           case 3:
-             if (TREE_CODE (type) != POINTER_TYPE
-                 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
-                 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
-                     != char_type_node))
-               pedwarn ("third argument of %q+D should probably be "
-                        "%<char **%>", decl1);
-             break;
-           }
-       }
-
-      /* It is intentional that this message does not mention the third
-        argument because it's only mentioned in an appendix of the
-        standard.  */
-      if (argct > 0 && (argct < 2 || argct > 3))
-       pedwarn ("%q+D takes only zero or two arguments", decl1);
+      check_main_parameter_types(decl1);
 
       if (!TREE_PUBLIC (decl1))
        pedwarn ("%q+D is normally a non-static function", decl1);
index b705968d04caff0226e6f1bf987f34111b17f509..ad1f12681e59ac23ec5b1a82e2b9aa84410d390c 100644 (file)
@@ -1,3 +1,8 @@
+2006-10-30  Dirk Mueller  <dmueller@suse.de>
+
+       PR c++/6321
+       * decl.c (grokfndecl): Use check_main_parameter_types.
+
 2006-10-30  Dirk Mueller  <dmueller@suse.de>
 
        PR c++/28669
index 2645da28295a2d327c5046d9cccbb9a5f7ef78a4..846089b52c17c93106f8a6971d288c820a97b3c1 100644 (file)
@@ -6027,6 +6027,7 @@ grokfndecl (tree ctype,
                                          oldtypeargs);
          TREE_TYPE (decl) = newtype;
        }
+      check_main_parameter_types (decl);
       inlinep = 0;
       publicp = 1;
     }