CVS-19981219: New PATCH for actually fixing the "main(){}" case
Manfred Hollstein
manfred@s-direktnet.de
Sat Jan 16 09:37:00 GMT 1999
Jason, any opinion about the patch below?
Thanks
manfred
On Sat, 19 December 1998, 20:14:43, manfred@s-direktnet.de wrote:
> On nil, 17 December 1998, 09:48:15, jason@cygnus.com wrote:
>
> > No; we want -Wreturn-type to warn about this case. It ought to be a plain
> > warning, though.
> >
> > Jason
>
> OK. How about this, then?
>
> 1998-12-19 Manfred Hollstein <manfred@s-direktnet.de>
>
> * decl.c (user_wants_pedantic_errors): Define new variable.
> (init_decl_processing): Record the current value of flag_pedantic_errors.
> (grokdeclarator): Define new helper variable `is_main'; decide based on
> `user_wants_pedantic_errors' if "main () { ... }" should be flagged with
> an error message or with a warning only.
>
> diff -rup -x CVS -x RCS -x *.o -x *.info* -x *.html* -x *.elc -x *.dvi -x *.orig -x *~ -x version.el egcs-19981219.orig/gcc/cp/decl.c egcs-19981219/gcc/cp/decl.c
> --- egcs-19981219.orig/gcc/cp/decl.c Sat Dec 19 10:24:37 1998
> +++ egcs-19981219/gcc/cp/decl.c Sat Dec 19 19:16:52 1998
> @@ -435,6 +435,9 @@ static struct named_label_list *named_la
> in the TREE_PURPOSE slot. */
> tree static_aggregates;
>
> +/* Record if the user specified -pedantic-errors. */
> +static int user_wants_pedantic_errors = 0;
> +
> /* -- end of C++ */
>
> /* Two expressions that are constants with value zero.
> @@ -5830,6 +5833,10 @@ init_decl_processing ()
>
> if (flag_strict_prototype == 2)
> flag_strict_prototype = pedantic;
> + /* Record if the user gave the -pedantic-errors flag; we will need this
> + later to decide, if "main () { ... }" should be flagged with an error
> + or with a warning only. */
> + user_wants_pedantic_errors = flag_pedantic_errors;
> if (! flag_permissive && ! pedantic)
> flag_pedantic_errors = 1;
>
> @@ -9353,16 +9360,24 @@ grokdeclarator (declarator, declspecs, d
> }
> else
> {
> - if (! pedantic && ! warn_return_type
> - && funcdef_flag
> - && MAIN_NAME_P (dname)
> - && ctype == NULL_TREE
> - && in_namespace == NULL_TREE
> - && current_namespace == global_namespace)
> + int is_main = funcdef_flag
> + && MAIN_NAME_P (dname)
> + && ctype == NULL_TREE
> + && in_namespace == NULL_TREE
> + && current_namespace == global_namespace;
> +
> + if (! pedantic && ! warn_return_type && is_main)
> /* Let `main () { }' slide, since it's so common. */;
> else
> - cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type",
> - dname);
> + {
> + int old_flag_pedantic_errors = flag_pedantic_errors;
> +
> + if (is_main)
> + flag_pedantic_errors = 0;
> + cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type",
> + dname);
> + flag_pedantic_errors = old_flag_pedantic_errors;
> + }
> type = integer_type_node;
> }
> }
>
More information about the Gcc-patches
mailing list