| Issue |
234962
|
| Summary |
[clang++] improper duplicate case value diagnostic when "did you mean" matches
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
dankamongmen
|
hello! this is valid in at least clang++ 21.1.8 through 23.1.3 as packaged in debian unstable's `clang-21` and `clang-23` packages, respectively.
if i have two `case` statements, and one of them references an undeclared enumeration, which `did you mean`-matches another `case` statement, a "duplicate case value" error is emitted treating the invalid reference as the matched reference. the order of the `case` statements doesn't matter.
minimum example:
```cpp
enum eenum {
E0,
EFLABBERJABBER,
};
int main(void){
eenum e = E0;
switch(e){
case EFLABBER2JABBER: break;
case EFLABBERJABBER: break;
}
return 0;
}
```
resulting diagnostics:
```
[schwarzgerat](0) $ clang++-23 -std=c++23 -Wall -W -g -O2 a.cpp
a.cpp:9:10: error: use of undeclared identifier 'EFLABBER2JABBER'; did you mean 'EFLABBERJABBER'?
9 | case EFLABBER2JABBER: break;
| ^~~~~~~~~~~~~~~
| EFLABBERJABBER
a.cpp:3:3: note: 'EFLABBERJABBER' declared here
3 | EFLABBERJABBER,
| ^
a.cpp:10:10: error: duplicate case value 'EFLABBERJABBER'
10 | case EFLABBERJABBER: break;
| ^
a.cpp:9:10: note: previous case defined here
9 | case EFLABBER2JABBER: break;
| ^
2 errors generated.
[schwarzgerat](1) $
```
if i replace `case(EFLABBER2JABBER)` with e.g. `case(E2)`, i just get the `use of undeclare identifier` (totally expected and valid). if i reorder the statements, we get:
```
a.cpp:10:10: error: use of undeclared identifier 'EFLABBER2JABBER'; did you mean 'EFLABBERJABBER'?
10 | case EFLABBER2JABBER: break;
| ^~~~~~~~~~~~~~~
| EFLABBERJABBER
a.cpp:3:3: note: 'EFLABBERJABBER' declared here
3 | EFLABBERJABBER,
| ^
a.cpp:10:10: error: duplicate case value 'EFLABBERJABBER'
10 | case EFLABBER2JABBER: break;
| ^
a.cpp:9:10: note: previous case defined here
9 | case EFLABBERJABBER: break;
| ^
2 errors generated.
```
so in both cases, it thinks the second `case` statement (line 10) is a duplicate of line 9, and that both are using the valid identifier. of course, they are different, and the "duplicate case value" diagnostic shouldn't be emitted in either case.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs