Bug 32161 - g++ fails to detect when int main() does not have a return statement
g++ fails to detect when int main() does not have a return statement
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2001-03-18 17:36 EST by Wagner T. Correa
Modified: 2007-04-18 12:32 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-03-18 17:36:47 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Wagner T. Correa 2001-03-18 17:36:22 EST
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 06:20:46 EST
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.