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

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

 



On Tuesday 15 November 2005 22:47, John Love-Jensen wrote:
> 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.

Yupp, that's what I currently do, in my case it unfortunately becomes a 
significant amount of code for dummy tests(because I know I'm behaving).


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