Subject: bin/2273: Revised warning for return types other than int from main.
To: None <gnats-bugs@NetBSD.ORG>
From: Peter Seebach <seebs@taniemarie.solon.com>
List: netbsd-bugs
Date: 03/30/1996 00:38:16
>Number: 2273
>Category: bin
>Synopsis: We should warn for non-int return types.
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sat Mar 30 02:05:21 1996
>Last-Modified:
>Originator: Peter Seebach
>Organization:
Usenet Fact Police (Undercover)
>Release: Mar 08
>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 is too stupid to warn for invalid return types on systems
where it has no default return. This patch warns for an invalid
return type, but does not provide a default return value; this way,
there's still a warning for not returning.
>How-To-Repeat:
test various source like
int main() {
}
or
void main() {
}
and notice that (with -Wall, for the first one) it'll warn.
>Fix:
Apply patch to common/c-decl.c.
*** c-decl.old Sat Mar 30 00:32:03 1996
--- c-decl.c Sat Mar 30 00:32:08 1996
***************
*** 6102,6107 ****
--- 6102,6114 ----
warning_with_decl (decl1,
"`%s' was used with no declaration before its definition");
+ if (! strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))))
+ {
+ if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
+ != integer_type_node)
+ warning_with_decl (decl1, "return type of `main' is not `int'");
+ }
+
/* This is a definition, not a reference.
So normally clear DECL_EXTERNAL.
However, `extern inline' acts like a declaration
>Audit-Trail:
>Unformatted: