Fix 9765: FP: knownConditionTrueFalse handling of template function with ternary operator (#3443)

This commit is contained in:
Paul Fultz II 2021-09-04 12:55:36 -05:00 committed by GitHub
parent 28bc717cbe
commit 928efe77fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -663,7 +663,7 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se
if (std::find(values.begin(), values.end(), value) != values.end())
setTokenValue(parent, value, settings);
}
} else {
} else if (!value.isImpossible()) {
// is condition only depending on 1 variable?
nonneg int varId = 0;
bool ret = false;

View File

@ -3223,6 +3223,14 @@ private:
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 13));
ASSERT_EQUALS(true, testValueOfX(code, 4U, 26));
code = "void f(int* i) {\n"
" if (!i) return;\n"
" int * x = *i == 1 ? i : nullptr;\n"
" int* a = x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 0));
ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0));
}
void valueFlowForwardLambda() {