public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/3622: g++ (but not gcc) thinks exit() returns
@ 2001-07-09 7:16 Grant Gould
0 siblings, 0 replies; only message in thread
From: Grant Gould @ 2001-07-09 7:16 UTC (permalink / raw)
To: gcc-gnats; +Cc: gildea
>Number: 3622
>Category: c++
>Synopsis: "control reaches end of non-void function" after exit()
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Mon Jul 09 07:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Grant Gould
>Release: 3.0
>Organization:
Comverse Voice Solutions
>Environment:
System: SunOS curley.intouchsys.com 5.7 Generic_106541-15 sun4m sparc SUNW,SPARCstation-5
Architecture: sun4
host: sparc-sun-solaris2.7
build: sparc-sun-solaris2.7
target: sparc-sun-solaris2.7
configured with: ../gcc-3.0/configure
>Description:
g++ gives a "warning: control reaches end of non-void function" in a
function that non-void function that may call exit(), unless exit() is
followed by a (clearly nonsensical) return statement.
gcc is not similarly afflicted.
>How-To-Repeat:
Compile the following simple program:
#include <stdlib.h>
int foo(int x)
{
if(x)
exit(0);
else
return 0;
}
You will get something like:
$ curley $ g++ hworld6.cpp -Wall -c -o hworld.o
hworld6.cpp: In function `int foo(int)':
hworld6.cpp:9: warning: control reaches end of non-void function
Whereas in fact it is clear that control never reaches the end of the
function. In fact, an even simpler function, like:
int foo(x) { exit(0); }
will exhibit the same problem, although that is more easily worked
around by changing the return type to void.
If you compile the same code with gcc, the warning vanishes:
$ curley $ cp hworld6.cpp hworld6.c
$ curley $ gcc hworld6.c -Wall -c -o hworld
>Fix:
g++ should behave like gcc in this case, regarding exit() as a
nonreturning function.
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2001-07-09 7:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-09 7:16 c++/3622: g++ (but not gcc) thinks exit() returns Grant Gould
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).