This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: False positive warning: missing return statement and switch statements
- From: "Steven L. Zook" <SLZook at Qualstar dot com>
- To: "Frans Englich" <frans dot englich at telia dot com>,<gcc-help at gcc dot gnu dot org>
- Date: Tue, 15 Nov 2005 14:26:59 -0800
- Subject: 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