https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70958
Bug ID: 70958
Summary: Flag -Wreturn-type does not warn about lacking return
statement in main
Product: gcc
Version: 5.3.1
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: carlos.maziero at gmail dot com
Target Milestone: ---
The GCC version provided with Ubuntu 16.04 (5.3.1 20160413) does not warn when
the main function lacks a return statement, when using -Wreturn-type or -Wall.
A minimum working example follows:
Code (mwe.c):
int main ()
{
int i = 1 ;
}
In GCC 5.3.1:
$ gcc mwe.c -Wreturn-type
$
In GCC 4.8.4 (Ubuntu 14.04):
$ gcc mwe.c -Wreturn-type
mwe.c: In function ‘main’:
mwe.c:4:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
$
The value returned by main is important in UNIX programs, as it is frequently
used as a return status for scripts.