[Lldb-commits] [lldb] [lldb] Add unreachable after fully covered switches, avoid GCC warnings. NFC. (PR #159327)
Martin Storsjö via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 17 05:29:05 PDT 2025
mstorsjo wrote:
> Taking one as an example:
>
> ```
> enum class FunctionNameRepresentation {
> eName,
> eNameWithArgs,
> eNameWithNoArgs
> };
> ```
>
> And we do have a return for each of the cases.
>
> So it feels like a limitation in GCC's analysis, is that right or did they make a decision to warn in these cases? I can see some value in making people mark the "unused" exit path like you might a fallthrough case.
See https://github.com/llvm/llvm-project/blob/main/llvm/docs/CodingStandards.rst#don-t-use-default-labels-in-fully-covered-switches-over-enumerations - the root cause here is that GCC assumes that an enum variable still technically can have any value outside of the enum, while Clang is ok with it.
> If you have some background on it please add it to the PR description. I'll probably want to cite it again at some point :)
> Also if we added an entry to one of these enums, would the "switch doesn't cover value" warning still happen? I think it would right?
Yes, we separately use `-Wswitch` which does produce this kind of warning with both GCC and Clang if we're missing enum elements in the switch:
```
../../lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:2181:11: warning: enumeration value 'eName' not handled in switch [-Wswitch]
2181 | switch (representation) {
| ^~~~~~~~~~~~~~
```
https://github.com/llvm/llvm-project/pull/159327
More information about the lldb-commits
mailing list