From cac68c6b81c36bac9a468fb89bd9f19ea8fd1f88 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Fri, 4 May 2018 00:58:30 -0500 Subject: [PATCH] Fix FP when using - as a binary operator (#1201) --- 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 7117b8acf..69ed67d4c 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 949bb5477..f1406748f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3955,6 +3955,9 @@ private: 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() {