Description
The following code triggers a missing return warning by gcc, msvc, and edg but not clang:
enum class E { a, b };
int foo(E e) {
switch(e) {
case E::a:
return 20;
case E::b:
return 30;
}
}
https://godbolt.org/z/b5r34nWf6
The main issue here is safety: This code is bug-prone due to extraneous enum values. The most common situation this could lead to bugs is for flag enums, e.g. https://godbolt.org/z/zx6nnPYMq.
Secondarily: This can lead to some annoyances where code compiles fine on clang but has a flood of warnings on gcc (possibly fatal ones, if using -Werror=return-type). This leads to PRs such as #122382 and #105520.
I'd like to propose changing the behavior to warn on this case by default. I briefly discussed this with folks on the llvm discord as well: https://discord.com/channels/636084430946959380/636732781086638081/1329124923322531850.