public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Steven L. Zook" <SLZook@Qualstar.com>
To: "Frans Englich" <frans.englich@telia.com>, <gcc-help@gcc.gnu.org>
Subject: RE: False positive warning: missing return statement and switch statements
Date: Tue, 15 Nov 2005 22:27:00 -0000	[thread overview]
Message-ID: <9E27B4AB55478346B9F7848926E49B7F011128A4@exchange1.qualstar.com> (raw)

What happens when someone calls with:

toInt( (Number)3 );

C/C++ lets you cast any numeric to an enum.

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Frans Englich
Sent: Tuesday, November 15, 2005 2:21 PM
To: gcc-help@gcc.gnu.org
Subject: False positive warning: missing return statement and switch
statements


Hello,

For the code below, when I invoke "g++ -Wall file.cpp" with GCC version
3.3.4, I get:

file.cpp: In function `int toInt(Number)':
file.cpp:20: warning: control reaches end of non-void function

------------------------------------------------------------------------
-
enum Number
{
        Zero,
        One,
        Two
};

int toInt(const Number num)
{
        switch(num)
        {
                case Zero:
                        return 0;
                case One:
                        return 1;
                case Two:
                        return 2;
        }
}

int main()
{
        Number num = Zero;
        return toInt(num);
}
------------------------------------------------------------------------
-

I don't understand why the warning is issued. Isn't it fair to assume
that the argument(const Number num) is correct since it is strongly
typed, by being an enumerator?


Cheers,

		Frans

             reply	other threads:[~2005-11-15 22:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-15 22:27 Steven L. Zook [this message]
2005-11-15 22:40 ` Frans Englich
2005-11-15 22:47   ` John Love-Jensen
2005-11-15 22:49     ` Frans Englich
  -- strict thread matches above, loose matches on Subject: below --
2005-11-15 23:26 Steven L. Zook
2005-11-15 23:31 ` Frans Englich
2005-11-15 22:10 Frans Englich

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=9E27B4AB55478346B9F7848926E49B7F011128A4@exchange1.qualstar.com \
    --to=slzook@qualstar.com \
    --cc=frans.englich@telia.com \
    --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).