llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.64k stars 11.84k forks source link

Conflicting warnings when handling enums in a switch with -Weverything #81354

Closed StreetwareGames closed 8 months ago

StreetwareGames commented 8 months ago

foo() warns about a default case missing, while foo2() warns about a default case being present when every enum case is already handled.

https://godbolt.org/z/WxooaoeMK

llvmbot commented 8 months ago

@llvm/issue-subscribers-clang-frontend

Author: None (SewerDweller)

foo() warns about a default case missing, while foo2() warns about a default case being present when every enum case is already handled. https://godbolt.org/z/WxooaoeMK
cor3ntin commented 8 months ago

Hum, this is actually consistent with GCC https://godbolt.org/z/re8Y5W1Wv and it is a separate flag from -Wswitch. I now remember that it was the intent of this flag (and note that it is not enabled under -Wall, -Wextra

cor3ntin commented 8 months ago

This was added by https://github.com/llvm/llvm-project/pull/73077

jyknight commented 8 months ago

This is correct. Some users want one, and some want the other, so both are provided.

It is expected behavior for -Weverything to include contradicting diagnostics, see the docs. As the docs also mention, it's not recommended to use -Weverything.

shafik commented 7 months ago

This stackexchange answer is also worth a read: https://softwareengineering.stackexchange.com/a/124574/84604