Fixed #11593 (function pointer => false negatives (ast? valueflow?))

This commit is contained in:
Daniel Marjamäki 2023-03-02 20:08:22 +01:00
parent 17e776861e
commit cfba046408
2 changed files with 21 additions and 0 deletions

View File

@ -1400,6 +1400,24 @@ static Token * findAstTop(Token *tok1, Token *tok2)
static Token * createAstAtToken(Token *tok, bool cpp)
{
// skip function pointer declaration
if (Token::Match(tok, "%type%") && !Token::Match(tok, "return|throw|if|while")) {
const Token* type = tok;
while (Token::Match(type, "%type%|*|&|<")) {
if (type->str() == "<") {
if (type->link())
type = type->link();
else
break;
}
type = type->next();
}
if (Token::simpleMatch(type, "(") &&
Token::Match(type->link()->previous(), "%var% ) (") &&
Token::Match(type->link()->linkAt(1), ") [;,)]"))
return type->link()->linkAt(1)->next();
}
if (Token::simpleMatch(tok, "for (")) {
if (cpp && Token::Match(tok, "for ( const| auto &|&&| [")) {
Token *decl = Token::findsimplematch(tok, "[");

View File

@ -6270,6 +6270,9 @@ private:
ASSERT_EQUALS("vary=", testAst("std::string var = y;"));
ASSERT_EQUALS("", testAst("void *(*var)(int);"));
// create ast for decltype
ASSERT_EQUALS("decltypex( var1=", testAst("decltype(x) var = 1;"));
ASSERT_EQUALS("a1bdecltypet((>2,(", testAst("a(1 > b(decltype(t)), 2);")); // #10271