| Issue |
241751
|
| Summary |
Disable unreachable-code diagnostic on speficic constants/comparison
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
fekir
|
I have following pattern
```c++
// generated at configure time
// depends on platform/compiler flags
enum class platform{
windows, debian, bsd, android, ...
current = windows,
};
void foo();
void bar();
void baz1(bool condition){
if(platform::current != platform::windows && condition){
foo();
} else if (!condition) {
bar();
}
}
```
but with `-Wunreachable-code`, clang diagnoses
```
<source>:16:9: warning: code will never be executed [-Wunreachable-code]
16 | foo();
| ^~~
<source>:15:50: warning: code will never be executed [-Wunreachable-code]
15 | if(platform::current != platform::windows && condition){
| ^~~~~~~~~
```
Note that (currently) the warning is not triggered for a `switch` statement, but transforming an `if` to a `switch` is error-prone, and does in general not improve the legibility.
```c++
void baz2(bool condition){
switch(platform::current){
case platform::windows: if(!condition) bar(); break;
default: if(condition) foo(); else bar(); break;
}
}
```
It is possible to suppress the warning locally with a `pragma`, but adding such `pragma`to every if-statement is repetitive and error-prone.
Is there a way to tell clang that the constant value `platform::current` depends on the compiler settings, and branches that depend on it are not necessarily dead?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs