False positive warning: missing return statement and switch statements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux