Control reaches end of non-void function: why only a warning?

Ryan Mansfield RMansfield@qnx.com
Tue Nov 15 18:15:00 GMT 2005


If you want to be forced then turn the warning into an error with -Werror

Regards,
 
Ryan Mansfield

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Pierre Sarrazin
Sent: Tuesday, November 15, 2005 1:03 PM
To: gcc-help@gcc.gnu.org
Subject: Re: Control reaches end of non-void function: why only a warning?

Dixit Oliver Kullmann (2005-11-15 16:30):
> On Tue, Nov 15, 2005 at 11:23:15AM -0500, Pierre Sarrazin wrote:
> > The following code generates the warning "control reaches end of
> > non-void function" under g++ 3.4.2:
> > 
> > int g()
> > {
> > }
> > 
> > Why is this only a warning and not an error?
> 
> Simply because this is legal code.

Interesting.  Do you happen to have a source I could go read myself?
It seems like I need a refresher course...

I asked someone to compile this code under Visual Studio .Net and
that compiler gives an error (C4716: "must return a value").

I understand that we sometimes want to code functions like this one:

int f()
{
    exit(1);
}

But that seems relatively rare, and I for one would not mind being
forced to add a dummy return statement after the call to exit().
The benefit of having a more rigorous compiler would outweigh this
slight inconvenience.

-- 
Pierre Sarrazin <sarrazip at sympatico dot ca>



More information about the Gcc-help mailing list