Issue |
123153
|
Summary |
Clang does not warn about missing returns when a switch statement covers all enum values
|
Labels |
clang
|
Assignees |
|
Reporter |
jeremy-rifkin
|
The following code triggers a missing return warning by gcc, msvc, and edg but not clang:
```cpp
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 https://github.com/llvm/llvm-project/pull/122382 and https://github.com/llvm/llvm-project/pull/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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs