Skip to content

Commit 928efe7

Browse files
authored
Fix 9765: FP: knownConditionTrueFalse handling of template function with ternary operator (#3443)
1 parent 28bc717 commit 928efe7

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se
663663
if (std::find(values.begin(), values.end(), value) != values.end())
664664
setTokenValue(parent, value, settings);
665665
}
666-
} else {
666+
} else if (!value.isImpossible()) {
667667
// is condition only depending on 1 variable?
668668
nonneg int varId = 0;
669669
bool ret = false;

test/testvalueflow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3223,6 +3223,14 @@ class TestValueFlow : public TestFixture {
32233223
"}";
32243224
ASSERT_EQUALS(false, testValueOfX(code, 4U, 13));
32253225
ASSERT_EQUALS(true, testValueOfX(code, 4U, 26));
3226+
3227+
code = "void f(int* i) {\n"
3228+
" if (!i) return;\n"
3229+
" int * x = *i == 1 ? i : nullptr;\n"
3230+
" int* a = x;\n"
3231+
"}\n";
3232+
ASSERT_EQUALS(true, testValueOfX(code, 4U, 0));
3233+
ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0));
32263234
}
32273235

32283236
void valueFlowForwardLambda() {

0 commit comments

Comments
 (0)