Issue 180429
Summary Logical inversion in diagnostic location for multiple 'default' labels in a switch statement
Labels new issue
Assignees
Reporter pengyuxiao
    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:
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).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to