Fix issue 8932: False positive knownConditionTrueFalse - valueflow ignores operator < (#1584)

This commit is contained in:
Paul Fultz II 2019-01-11 01:39:23 -06:00 committed by amai2012
parent 400c6c8e76
commit 5fa956a597
2 changed files with 12 additions and 1 deletions

View File

@ -1153,7 +1153,7 @@ static void valueFlowSameExpressions(TokenList *tokenlist)
if (tok->astOperand1()->isLiteral() || tok->astOperand2()->isLiteral())
continue;
if (astIsFloat(tok->astOperand1(), true) || astIsFloat(tok->astOperand2(), true))
if (!astIsIntegral(tok->astOperand1(), false) && !astIsIntegral(tok->astOperand2(), false))
continue;
ValueFlow::Value val;

View File

@ -2774,6 +2774,17 @@ private:
check("void f(const int a[]){ if (a == 0){} }");
ASSERT_EQUALS("", errout.str());
check("struct S {\n"
" bool operator<(const S&);\n"
"};\n"
"int main() {\n"
" S s;\n"
" bool c = s<s;\n"
" if (c) return 0;\n"
" else return 42;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void multiConditionAlwaysTrue() {