Logical inversion in diagnostic location for multiple 'default' labels in a switch statement
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When multiple default labels are present in a single switch statement, Clang points the primary error diagnostic to the first occurrence. Logically, the first default label is perfectly valid; the program only becomes invalid when the second (duplicate) default label is encountered.
This creates a misleading debugging experience. In large, generated files, the developer is told that a valid line of code is an error, rather than being told that a later line is a duplicate of the first.
Minimal Reproducible Example:
```cpp
void f(int x) {
switch (x) {
default: break; // Line 3: Valid
case 1: break;
default: break; // Line 5: The actual duplicate/violation
}
}
```
Actual Behavior (Clang): Reports an error at Line 3.
Expected Behavior: The primary error should be at Line 5, with a supporting note pointing back to Line 3. This would align with how Clang handles other redefinition errors (e.g., duplicate function or variable definitions).
Contributor guide
Assessment
This issue has not been assessed yet.