diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 645b7addd..353b820fc 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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, "["); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index de7fe4400..2c1c89a07 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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