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 switchstatements
- From: John Love-Jensen <eljay at adobe dot com>
- To: Frans Englich <frans dot englich at telia dot com>, "Steven L. Zook" <SLZook at qualstar dot com>
- Cc: MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Tue, 15 Nov 2005 16:47:05 -0600
- Subject: Re: False positive warning: missing return statement and switchstatements
Hi Frans,
> Obviously, I am looking at this the wrong way -- please explain.
Improve your code safety using C++ capabilities:
int toInt(const Number num)
{
switch(num)
{
case Zero:
return 0;
case One:
return 1;
case Two:
return 2;
default:
throw std::range_error("toInt(): enum Number out of range");
}
}
Then the warning goes away, and your code is better.
Sincerely,
--Eljay