Bug 32161 - g++ fails to detect when int main() does not have a return statement
Summary: g++ fails to detect when int main() does not have a return statement
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-03-18 22:36 UTC by Wagner T. Correa
Modified: 2007-04-18 16:32 UTC (History)
1 user (show)

(edit)
Clone Of:
(edit)
Last Closed: 2001-03-18 22:36:47 UTC


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.