From caeae082d96e5637b52555401c94d3c97fbdd0bf Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 3 May 2018 18:37:22 -0500 Subject: [PATCH] Fix FP when using - as a binary operator --- lib/astutils.cpp | 4 ++-- test/testother.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 7117b8acf8d..69ed67d4c1c 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -365,9 +365,9 @@ bool isOppositeExpression(bool cpp, const Token * const tok1, const Token * cons return false; if (isOppositeCond(true, cpp, tok1, tok2, library, pure)) return true; - if (tok1->str() == "-") + if (tok1->str() == "-" && !tok1->astOperand2()) return isSameExpression(cpp, true, tok1->astOperand1(), tok2, library, pure); - if (tok2->str() == "-") + if (tok2->str() == "-" && !tok1->astOperand2()) return isSameExpression(cpp, true, tok2->astOperand1(), tok1, library, pure); return false; } diff --git a/test/testother.cpp b/test/testother.cpp index 949bb547701..f1406748f30 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3955,6 +3955,9 @@ class TestOther : public TestFixture { check("void f(int a) { a = a / (-a); }"); ASSERT_EQUALS("", errout.str()); + + check("bool f(int i){ return !((i - 1) & i); }"); + ASSERT_EQUALS("", errout.str()); } void duplicateVarExpression() {