c++/3622: g++ (but not gcc) thinks exit() returns

Grant Gould ggould@intouchsys.com
Mon Jul 9 07:16:00 GMT 2001


>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:



More information about the Gcc-bugs mailing list