I have some c++ code where I switch over values in an enum. I was trying to compile this with -Wall -Wextra -Werror. This is fine when using clang. GCC, however, complains that the default code path is not covered. A simplified version looks as follows:
enum class Types: int {
A,
B,
C
};
bool some_logic(Types val) {
switch (val) {
case Types::A:
return (false);
case Types::B:
return (true);
case Types::C:
return (false);
}
}
I can handle this by adding a default case, or another return statement at the end of the function. However, my question was why doesn't GCC detect that all of the cases of the enum are covered? Or phrased differently, is there a legitimate reason for GCC to complain here?
I've put a comparison of the compiler outputs here.