This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

CVS-19981216: PATCH for actually fixing the "main(){}" case


Reading the comments in gcc/cp/ChangeLog and gcc/cp/decl.c makes me believe,
"main () { ... }" should be compiled without a warning:

  1998-11-22  Jason Merrill  <jason@yorick.cygnus.com>

	* decl.c: Lose warn_about_return_type.
	(grokdeclarator): Always complain about implicit int, except for
	`main () { ... }'.

and from grokdeclarator() in gcc/cp/decl.c:

    	    /* Let `main () { }' slide, since it's so common.  */;

But, compiling this small example:

  main () {}

actually results in:

$ gcc t012.cc
$ echo $?
0
$ gcc -Wall t012.cc
t012.cc:2: ANSI C++ forbids declaration `main' with no type
$ echo $?
1
$ gcc -pedantic t012.cc
t012.cc:2: warning: ANSI C++ forbids declaration `main' with no type
$ echo $?
0
$ 

Interestingly, -Wall makes it an error, while -pedantic let's it survive
as a warning message. The small patch below makes g++ behave as the
comments suppose it should.

manfred


1998-12-16  Manfred Hollstein  <manfred@s-direktnet.de>

	* decl.c (grokdeclarator): Actually fix the `do not warn for
	"main () { ... }" case'.
	
diff -rup -x CVS -x RCS -x *.o -x *.info* -x *.html* -x *.elc -x *.dvi -x *.orig -x *~ -x version.el egcs-19981216.orig/gcc/cp/decl.c egcs-19981216/gcc/cp/decl.c
--- egcs-19981216.orig/gcc/cp/decl.c	Wed Dec 16 21:26:11 1998
+++ egcs-19981216/gcc/cp/decl.c	Thu Dec 17 12:15:24 1998
@@ -9345,7 +9345,7 @@ grokdeclarator (declarator, declspecs, d
 	}
       else
 	{
-	  if (! pedantic && ! warn_return_type
+	  if (! pedantic
 	      && funcdef_flag
 	      && MAIN_NAME_P (dname)
 	      && ctype == NULL_TREE


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]