If I have a function that returns based on switching over a enum class, gcc emits warning: control reaches end of non-void function [-Wreturn-type]. Example code:
enum class Test { a, b, c } ;
int foo(Test test) {
switch (test) {
case Test::a: return 0;
case Test::b: return 1;
case Test::c: return 2;
}
}
I have thought of two solutions but neither seem correct:
1) have a default case that throws. However, when I add an additional member to the enum class I no longer receive an error that I missed a case.
2) Suppress the warning with a pragma, but then I don't guard against someone passing in a static_cast<Test>(123).
So my question is, how to deal with -Wreturn-type errors for switch over C++11 enum class?