Skip to content

Commit f034ad3

Browse files
Fix #14762 FN knownConditionTrueFalse (default constructed container) (#8575)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 15a4191 commit f034ad3

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/vf_settokenvalue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ namespace ValueFlow
291291

292292
combineValueProperties(value1, value2, result);
293293

294-
if (Token::simpleMatch(parent, "==") && result.intvalue)
294+
if (Token::simpleMatch(parent, "==") && result.intvalue && !(value1.intvalue == 0 && value2.intvalue == 0))
295295
continue;
296-
if (Token::simpleMatch(parent, "!=") && !result.intvalue)
296+
if (Token::simpleMatch(parent, "!=") && !result.intvalue && !(value1.intvalue == 0 && value2.intvalue == 0))
297297
continue;
298298

299299
setTokenValue(parent, std::move(result), settings);

test/testvalueflow.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9249,6 +9249,19 @@ class TestValueFlow : public TestFixture {
92499249
"}\n";
92509250
ASSERT_EQUALS(false, testValueOfX(code, 5U, 1));
92519251
ASSERT_EQUALS(false, testValueOfX(code, 5U, 0));
9252+
9253+
code = "bool f() {\n"
9254+
" std::string s1, s2;\n"
9255+
" bool x = (s1 == s2);\n"
9256+
" return x;\n"
9257+
"}\n"
9258+
"bool g() {\n"
9259+
" std::string s1, s2;\n"
9260+
" bool x = (s1 != s2);\n"
9261+
" return x;\n"
9262+
"}\n";
9263+
ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 1));
9264+
ASSERT_EQUALS(true, testValueOfXKnown(code, 9U, 0));
92529265
}
92539266

92549267
void valueFlowBailoutIncompleteVar() {

0 commit comments

Comments
 (0)