From b46e25c18e514f587e54748e0f0b382a9a290882 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Wed, 5 Sep 2018 11:07:01 -0500 Subject: [PATCH] Fix issue 8730: False positive: Opposite expression on both sides of && (#1366) --- lib/astutils.cpp | 3 +++ test/testother.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index b5a0aead4..135089569 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -212,6 +212,9 @@ static const Token * followVariableExpression(const Token * tok, bool cpp) return tok; if (!var2->isConst() && isVariableChanged(tok2, endToken2, tok2->varId(), false, nullptr, cpp)) return tok; + // Recognized as a variable but the declaration is unknown + } else if(tok2->varId() > 0) { + return tok; } } return varTok; diff --git a/test/testother.cpp b/test/testother.cpp index fa23563c3..ab006538e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4256,6 +4256,14 @@ private: check("bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }"); ASSERT_EQUALS("", errout.str()); + + check("void A::f(bool a, bool c)\n" + "{\n" + " const bool b = a;\n" + " if(c) { a = false; } \n" + " if(b && !a) { }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void duplicateVarExpression() {