-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Closed as not planned
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerduplicateResolved as duplicateResolved as duplicate
Description
With clang 18, when using the -Weverything flag with code involving switches, I get switch-related warnings no matter what I do.
If the switches are exhaustive. clang -Weverything complains the switch is missing a default:
$ cat test.c
#include <assert.h>
typedef enum {
ZERO = 0,
ONE = 1,
} Number;
int test(Number number);
int test(Number number)
{
switch (number)
{
case ZERO:
return 0;
case ONE:
return 1;
}
assert(0);
return -1;
}
$ clang -c test.c -o test.o -Wall -Weverything
test.c:13:2: warning: 'switch' missing 'default' label [-Wswitch-default]
13 | switch (number)
| ^
1 warning generated.
When default is present, clang complains that the switch is exhaustive and default shouldn't be used:
$ cat test.c
#include <assert.h>
typedef enum {
ZERO = 0,
ONE = 1,
} Number;
int test(Number number);
int test(Number number)
{
switch (number)
{
case ZERO:
return 0;
case ONE:
return 1;
default:
assert(0);
return -1;
}
assert(0);
return -1;
}
$ clang -c test.c -o test.o -Wall -Weverything
test.c:19:3: warning: default label in switch which covers all enumeration values [-Wcovered-switch-default]
19 | default:
| ^
1 warning generated.
What can I do to make clang happy?
Environment:
$ clang --version
clang version 18.1.0 (Fedora 18.1.0~rc4-2.fc40)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Configuration file: /etc/clang/clang.cfg
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerduplicateResolved as duplicateResolved as duplicate