AST: do not produce AST for function pointer declaration 'void *(*var[2])(int)'

This commit is contained in:
Daniel Marjamäki 2023-03-04 11:09:42 +01:00
parent f4e0ae3b84
commit 350a1f2dfc
2 changed files with 4 additions and 3 deletions

View File

@ -1402,7 +1402,7 @@ static Token * findAstTop(Token *tok1, Token *tok2)
static Token * createAstAtToken(Token *tok, bool cpp) static Token * createAstAtToken(Token *tok, bool cpp)
{ {
// skip function pointer declaration // skip function pointer declaration
if (Token::Match(tok, "%type%") && !Token::Match(tok, "return|throw|if|while")) { if (Token::Match(tok, "%type%") && !Token::Match(tok, "return|throw|if|while|new|delete")) {
const Token* type = tok; const Token* type = tok;
while (Token::Match(type, "%type%|*|&|<")) { while (Token::Match(type, "%type%|*|&|<")) {
if (type->str() == "<") { if (type->str() == "<") {
@ -1413,8 +1413,8 @@ static Token * createAstAtToken(Token *tok, bool cpp)
} }
type = type->next(); type = type->next();
} }
if (Token::simpleMatch(type, "(") && if (Token::Match(type, "( * *| %var%") &&
Token::Match(type->link()->previous(), "%var% ) (") && Token::Match(type->link()->previous(), "%var%|] ) (") &&
Token::Match(type->link()->linkAt(1), ") [;,)]")) Token::Match(type->link()->linkAt(1), ") [;,)]"))
return type->link()->linkAt(1)->next(); return type->link()->linkAt(1)->next();
} }

View File

@ -6275,6 +6275,7 @@ private:
ASSERT_EQUALS("vary=", testAst("std::string var = y;")); ASSERT_EQUALS("vary=", testAst("std::string var = y;"));
ASSERT_EQUALS("", testAst("void *(*var)(int);")); ASSERT_EQUALS("", testAst("void *(*var)(int);"));
ASSERT_EQUALS("", testAst("void *(*var[2])(int);"));
// create ast for decltype // create ast for decltype