Subject: standards/2243: gcc is not providing a useful warning.
To: None <gnats-bugs@NetBSD.ORG>
From: Peter Seebach <seebs@taniemarie.solon.com>
List: netbsd-bugs
Date: 03/20/1996 22:51:59
>Number: 2243
>Category: standards
>Synopsis: gcc does not warn for invalid return types of main
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: gnats-admin (GNATS administrator)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Thu Mar 21 00:05:01 1996
>Last-Modified:
>Originator: Peter Seebach
>Organization:
Usenet Fact Police (Undercover)
>Release: Mar 8, 1996
>Environment:
System: NetBSD taniemarie 1.1A NetBSD 1.1A (SEEBS) #0: Sat Mar 9 11:19:31 CST 1996 seebs@taniemarie:/usr/src/sys/arch/amiga/compile/SEEBS amiga
>Description:
gcc has code to warn if main is declared not to return an int, but
it is not enabled (by default) unless you are MVS or VMS. Since
NetBSD does use return statii, the warning is useful. It will also
help users detect common bugs.
>How-To-Repeat:
$ cat > t.c
void main(void) {}
^D
$ cc -Wall t.c
$
(Note: Yes, this is really illegal. No, ANSI does not require a
diagnostic, but yes, it really does invoke undefined behavior.)
>Fix:
Apply the following patch to /usr/src/gnu/usr.bin/gcc/arch/netbsd.h:
-----------------------------------------------------------------
*** netbsd.old Wed Mar 20 16:01:16 1996
--- netbsd.h Wed Mar 20 16:02:31 1996
***************
*** 4,9 ****
--- 4,11 ----
#ifdef NETBSD_NATIVE
+ #define DEFAULT_MAIN_RETURN c_expand_return (integer_zero_node)
+
/* Look for the include files in the system-defined places. */
#undef GPLUSPLUS_INCLUDE_DIR
-----------------------------------------------------------------
The number zero is arbitrary, and will cause programs to return
"success". Arguably, "integer_one_node" would be better, because it would
cause the bug in such programs (those forgetting to return a value) to
register as failing.
This is under standards solely because it is a way for us to detect behavior
(like declaring main to return void, double, or struct {...}) which is not
legal under ANSI, although most of it "works" fine on NetBSD. The warning
would be a great boon to software folks, especially us pedants.
I have tested this, and a large number of applications build ok with this;
it may require some supplemental patches for programs which misdeclare
main.
-s
>Audit-Trail:
>Unformatted: