False positive warning: missing return statement and switch statements
Frans Englich
frans.englich@telia.com
Tue Nov 15 22:10:00 GMT 2005
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
More information about the Gcc-help
mailing list