This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: False positive warning: missing return statement and switch statements


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]