Skip to content

Commit 7618e10

Browse files
authored
Do not add AST for pointer in variable declaration (#5593)
1 parent 1284470 commit 7618e10

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/tokenlist.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,14 @@ static Token * findAstTop(Token *tok1, const Token *tok2)
14451445
static Token * createAstAtToken(Token *tok, bool cpp)
14461446
{
14471447
// skip function pointer declaration
1448+
if (Token::Match(tok, "%type% %type%") && !Token::Match(tok, "return|throw|new|delete")) {
1449+
Token* tok2 = tok->tokAt(2);
1450+
// skip type tokens and qualifiers etc
1451+
while (Token::Match(tok2, "%type%|*|&"))
1452+
tok2 = tok2->next();
1453+
if (Token::Match(tok2, "%var% [;,)]"))
1454+
return tok2;
1455+
}
14481456
if (Token::Match(tok, "%type%") && !Token::Match(tok, "return|throw|if|while|new|delete")) {
14491457
Token* type = tok;
14501458
while (Token::Match(type, "%type%|*|&|<")) {

test/testtokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6474,6 +6474,9 @@ class TestTokenizer : public TestFixture {
64746474
ASSERT_EQUALS("tmpa*=a*b*=,b*tmp=,", testAst("{ ((tmp) = (*a)), ((*a) = (*b)), ((*b) = (tmp)); }"));
64756475
ASSERT_EQUALS("a(*v=", testAst("(*(volatile unsigned int *)(a) = (v));"));
64766476
ASSERT_EQUALS("i(j=", testAst("(int&)(i) = j;"));
6477+
6478+
ASSERT_EQUALS("", testAst("void f(enum E* var){}"));
6479+
ASSERT_EQUALS("", testAst("void f(enum E*& var){}"));
64776480
}
64786481

64796482
void astunaryop() const { // unary operators

0 commit comments

Comments
 (0)