Issue |
145506
|
Summary |
Missing warning if variable is used in else clause of if (type_t var = ...)
|
Labels |
new issue
|
Assignees |
|
Reporter |
Alcaro
|
```c++
int* get_something();
int* get_something_else();
int square() {
if (int* ptr1 = get_something())
return ptr1[0] * ptr1[0];
else if (int* ptr2 = get_something_else())
return ptr1[0] * ptr2[0]; // whoops, typoed!
else
return -1;
}
```
Expected: Compiler warning about how ptr1 is always null on the commented line. (Simplifying the example further returns an unused-variable warning for ptr2; that's not what I'm asking for.)
Actual: No output, just pretends ptr1[0] is 0 and optimizes accordingly. (Ideally, ptr1 would only be in scope in its then-clause, not throughout the entire if-statement, but that's not how the C++ spec looks.)
https://godbolt.org/z/118vGjE43
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs