Fix issue 8730: False positive: Opposite expression on both sides of && (#1366)

This commit is contained in:
Paul Fultz II 2018-09-05 11:07:01 -05:00 committed by Daniel Marjamäki
parent 1d85a78874
commit b46e25c18e
2 changed files with 11 additions and 0 deletions

View File

@ -212,6 +212,9 @@ static const Token * followVariableExpression(const Token * tok, bool cpp)
return tok; return tok;
if (!var2->isConst() && isVariableChanged(tok2, endToken2, tok2->varId(), false, nullptr, cpp)) if (!var2->isConst() && isVariableChanged(tok2, endToken2, tok2->varId(), false, nullptr, cpp))
return tok; return tok;
// Recognized as a variable but the declaration is unknown
} else if(tok2->varId() > 0) {
return tok;
} }
} }
return varTok; return varTok;

View File

@ -4256,6 +4256,14 @@ private:
check("bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }"); check("bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }");
ASSERT_EQUALS("", errout.str()); 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() { void duplicateVarExpression() {