Fix false positive with oppositeExpression when using binary op (#1211)

* Fix false positive with oppositeExpression when using binary op

* Simplify conditional
This commit is contained in:
Paul Fultz II 2018-05-08 13:43:57 -05:00 committed by Daniel Marjamäki
parent d934065d21
commit f5dbfce8ff
2 changed files with 4 additions and 1 deletions

View File

@ -367,7 +367,7 @@ bool isOppositeExpression(bool cpp, const Token * const tok1, const Token * cons
return true;
if (tok1->str() == "-" && !tok1->astOperand2())
return isSameExpression(cpp, true, tok1->astOperand1(), tok2, library, pure);
if (tok2->str() == "-" && !tok1->astOperand2())
if (tok2->str() == "-" && !tok2->astOperand2())
return isSameExpression(cpp, true, tok2->astOperand1(), tok1, library, pure);
return false;
}

View File

@ -3958,6 +3958,9 @@ private:
check("bool f(int i){ return !((i - 1) & i); }");
ASSERT_EQUALS("", errout.str());
check("bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }");
ASSERT_EQUALS("", errout.str());
}
void duplicateVarExpression() {