diff --git a/lib/astutils.cpp b/lib/astutils.cpp index d25219a07..af0442619 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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; } diff --git a/test/testother.cpp b/test/testother.cpp index f1406748f..c0261afa2 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {