public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre Sarrazin <sarrazip@sympatico.ca>
To: gcc-help@gcc.gnu.org
Subject: Re: Control reaches end of non-void function: why only a warning?
Date: Tue, 15 Nov 2005 18:04:00 -0000	[thread overview]
Message-ID: <20051115180327.GA13059@localhost> (raw)
In-Reply-To: <20051115163046.GA4485@cs-wsok.swansea.ac.uk>

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>

  reply	other threads:[~2005-11-15 18:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-15 16:23 Pierre Sarrazin
2005-11-15 16:31 ` Oliver Kullmann
2005-11-15 18:04   ` Pierre Sarrazin [this message]
2005-11-15 18:15 Ryan Mansfield
2005-11-15 23:22 ` Pierre Sarrazin
2005-11-16  1:05 Ryan Mansfield
2005-11-16 14:41 ` Pierre Sarrazin
2005-11-16 15:00 Ryan Mansfield

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051115180327.GA13059@localhost \
    --to=sarrazip@sympatico.ca \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).