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() {