Skip to content

[clang] False-positive with -Wswitch-default and templates #75943

Closed
@al42and

Description

@al42and

Compiling the following code with Clang trunk and -Wswitch-default option produces "'switch' missing 'default' label" warning, despite the label clearly being there:

template<typename Index>
int f1(Index i)
{
    switch (i)
    {
        case 0: return 0;
        case 1: return 1;
        default: return 2;
    }
}
$ clang++ -fsyntax-only -Wswitch-default test.cpp 
test.cpp:4:5: warning: 'switch' missing 'default' label [-Wswitch-default]
    4 |     switch (i)
      |     ^
1 warning generated.

$ clang++ --version
clang version 18.0.0git (https://github.com/llvm/llvm-project.git c0d2ea9d4202c7cce4214b3057a709ff2f1128ae)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/aland/llvm-project/build/install//bin

Godbolt: https://godbolt.org/z/c3a695b5n

Related to #73077

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should not

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions