decl.c (grokdeclarator): Don't make 'main(){}' an error with only -Wreturn-type.
authorJason Merrill <jason@yorick.cygnus.com>
Sat, 16 Jan 1999 16:44:35 +0000 (16:44 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 16 Jan 1999 16:44:35 +0000 (11:44 -0500)
* decl.c (grokdeclarator): Don't make 'main(){}' an error with only
-Wreturn-type.

Co-Authored-By: Manfred Hollstein <manfred@s-direktnet.de>
From-SVN: r24704

gcc/cp/ChangeLog
gcc/cp/decl.c

index 32f5df1ce3848c0c1138490518631916da0ea6a9..554d85f5c32c2ec586bc4ad5811f0ce7753cf5e1 100644 (file)
@@ -1,3 +1,9 @@
+1999-01-16  Jason Merrill  <jason@yorick.cygnus.com>
+           Manfred Hollstein <manfred@s-direktnet.de>
+
+       * decl.c (grokdeclarator): Don't make 'main(){}' an error with only
+       -Wreturn-type.
+
 1999-01-16  Nathan Sidwell  <nathan@acm.org>
 
        * cp-tree.h (struct lang_type): Added has_mutable flag.
index b15cec558278e1b6f5267f064d3b9339428785b4..13c11bfcba7f6ae97482f8d2eb5485fd327c3002 100644 (file)
@@ -9356,16 +9356,22 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
        }
       else
        {
-         if (! pedantic && ! warn_return_type
-             && funcdef_flag
-             && MAIN_NAME_P (dname)
-             && ctype == NULL_TREE
-             && in_namespace == NULL_TREE
-             && current_namespace == global_namespace)
-           /* Let `main () { }' slide, since it's so common.  */;
-         else
+         /* We handle `main' specially here, because 'main () { }' is so
+            common.  With no options, it is allowed.  With -Wreturn-type,
+            it is a warning.  It is only an error with -pedantic-errors.  */
+         int is_main = (funcdef_flag
+                        && MAIN_NAME_P (dname)
+                        && ctype == NULL_TREE
+                        && in_namespace == NULL_TREE
+                        && current_namespace == global_namespace);
+
+         if (pedantic || ! is_main)
            cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type",
                        dname);
+         else if (warn_return_type)
+           cp_warning ("ANSI C++ forbids declaration `%D' with no type",
+                       dname);
+
          type = integer_type_node;
        }
     }