isConstVarExpression: Fix FPs when there is C++ cast

This commit is contained in:
Daniel Marjamäki 2019-01-01 11:34:44 +01:00
parent 04d3672bde
commit a73e989d1a
2 changed files with 9 additions and 0 deletions

View File

@ -1050,6 +1050,9 @@ bool isConstVarExpression(const Token *tok)
std::vector<const Token *> args = getArguments(tok);
return std::all_of(args.begin(), args.end(), &isConstVarExpression);
}
if (Token::simpleMatch(tok->previous(), "> (") && tok->astOperand2() && tok->astOperand1()->str().find("_cast") != std::string::npos) {
return isConstVarExpression(tok->astOperand2());
}
if (Token::Match(tok, "( %type%"))
return isConstVarExpression(tok->astOperand1());
if (Token::Match(tok, "%cop%")) {

View File

@ -7599,6 +7599,12 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("void g(Foo *);\n"
"void f() {\n"
" g(reinterpret_cast<Foo*>(0));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void g(int);\n"
"void f(int x) {\n"
" x = 0;\n"