diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 0b892cc98..1d27dc810 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1445,6 +1445,14 @@ static Token * findAstTop(Token *tok1, const Token *tok2) static Token * createAstAtToken(Token *tok, bool cpp) { // skip function pointer declaration + if (Token::Match(tok, "%type% %type%") && !Token::Match(tok, "return|throw|new|delete")) { + Token* tok2 = tok->tokAt(2); + // skip type tokens and qualifiers etc + while (Token::Match(tok2, "%type%|*|&")) + tok2 = tok2->next(); + if (Token::Match(tok2, "%var% [;,)]")) + return tok2; + } if (Token::Match(tok, "%type%") && !Token::Match(tok, "return|throw|if|while|new|delete")) { Token* type = tok; while (Token::Match(type, "%type%|*|&|<")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ab4ab531d..0f1f54c93 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6474,6 +6474,9 @@ private: ASSERT_EQUALS("tmpa*=a*b*=,b*tmp=,", testAst("{ ((tmp) = (*a)), ((*a) = (*b)), ((*b) = (tmp)); }")); ASSERT_EQUALS("a(*v=", testAst("(*(volatile unsigned int *)(a) = (v));")); ASSERT_EQUALS("i(j=", testAst("(int&)(i) = j;")); + + ASSERT_EQUALS("", testAst("void f(enum E* var){}")); + ASSERT_EQUALS("", testAst("void f(enum E*& var){}")); } void astunaryop() const { // unary operators