-
Notifications
You must be signed in to change notification settings - Fork 15k
Description
When having both -Wswitch-default and -Wcovered-switch-default this generates contradictory warnings. When you don't have a default case for a switch statement that handles every enum value you get a warning for not having it; and if you do you get a warning for having it. However you require both those flags if you wish to get related warnings elsewhere when dealing with switch statements not related to enums or enums but not all the values.
#include <cstdint>
enum class ETest : std::uint8_t
{
TEST1,
TEST2,
};
auto main() -> int
{
ETest test = ETest::TEST2;
[[maybe_unused]]
int a {};
switch (test)
{
case ETest::TEST1: a = 1; break;
case ETest::TEST2: a = 2; break;
// default: a = 99; break;
}
return 0;
}What I would expect is that -Wswitch-default is suppressed when dealing with enums and every case is covered, but active otherwise.
The way it is now, you will miss out on at least one of those three possible cases that require a warning:
- A
switchstatement that is not handling anenumdoesn't have adefaultcase (which is bad) - A
switchstatement that is dealing with anenumis fully defined but has adefaultcase (which is bad) - A
switchstatement that is dealing with anenumis not fully defined and doesn't have adefaultcase (which is bad)
This was not the case in earlier versions of clang, which handled this correctly.
My version is
Ubuntu clang version 19.0.0 (++20240222031214+307409a8872f-1~exp1~20240222151237.1514)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin