-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Open
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerundefined behaviour
Description
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.)
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerundefined behaviour