Fix issue 8730: Dont follow variables with unknown symbols (#1374)

This commit is contained in:
Paul Fultz II 2018-09-12 10:30:18 -05:00 committed by Daniel Marjamäki
parent 399a90c00e
commit 90a29d986b
2 changed files with 16 additions and 0 deletions

View File

@ -228,6 +228,8 @@ static const Token * followVariableExpression(const Token * tok, bool cpp, const
// Recognized as a variable but the declaration is unknown
} else if (tok2->varId() > 0) {
return tok;
} else if(tok2->tokType() == Token::eName && !Token::Match(tok2, "sizeof|decltype|typeof") && !tok2->function()) {
return tok;
}
}
return varTok;

View File

@ -4266,6 +4266,20 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f(bool c) {\n"
" const bool b = a;\n"
" if(c) { a = false; } \n"
" if(b && !a) { }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" bool x = a;\n"
" dostuff();\n"
" if (x && a) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" const bool b = g();\n"
" if (!b && g()) {}\n"