diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index c5fe519b720..fe94225083b 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -291,9 +291,9 @@ namespace ValueFlow combineValueProperties(value1, value2, result); - if (Token::simpleMatch(parent, "==") && result.intvalue) + if (Token::simpleMatch(parent, "==") && result.intvalue && !(value1.intvalue == 0 && value2.intvalue == 0)) continue; - if (Token::simpleMatch(parent, "!=") && !result.intvalue) + if (Token::simpleMatch(parent, "!=") && !result.intvalue && !(value1.intvalue == 0 && value2.intvalue == 0)) continue; setTokenValue(parent, std::move(result), settings); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index c879b9cffd5..3e10ffb9361 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -9225,6 +9225,19 @@ class TestValueFlow : public TestFixture { "}\n"; ASSERT_EQUALS(false, testValueOfX(code, 5U, 1)); ASSERT_EQUALS(false, testValueOfX(code, 5U, 0)); + + code = "bool f() {\n" + " std::string s1, s2;\n" + " bool x = (s1 == s2);\n" + " return x;\n" + "}\n" + "bool g() {\n" + " std::string s1, s2;\n" + " bool x = (s1 != s2);\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 1)); + ASSERT_EQUALS(true, testValueOfXKnown(code, 9U, 0)); } void valueFlowBailoutIncompleteVar() {