This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]