Bug 32161

Summary: g++ fails to detect when int main() does not have a return statement
Product: [Retired] Red Hat Linux Reporter: Wagner T. Correa <wtcorrea>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0CC: wtcorrea
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-03-18 22:36:47 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Wagner T. Correa 2001-03-18 22:36:22 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.2.16-22smp i686)


g++ detects when non-void functions do not have a return statement.
However, for some reason it does not detect when int main() does not return
a value.

Reproducible: Always
Steps to Reproduce:
int foo()
{
	// g++ detects lack of return statement here
}


int main ()
{
	// but doesn't detect it here
}


Actual Results:  y.cpp: In function `int foo ()':
y.cpp:4: warning: no return statement in function returning non-void


Expected Results:  I would expect to get for main the same warning that I
got for foo.

Comment 1 Jakub Jelinek 2001-03-19 11:20:46 UTC
No, this is correct. ISO C++ [basic.start.main]/5 sais that:
If control reached the end of main without encountering a return statement,
the effect is that of executing
        return 0;
For functions other than main, the standard requires non-void functions
to end with return statement.