Skip to content

Commit

Permalink
Do not add AST for pointer in variable declaration (danmar#5593)
Browse files Browse the repository at this point in the history
  • Loading branch information
swasti16 authored Oct 31, 2023
1 parent 1284470 commit 7618e10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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%|*|&|<")) {
Expand Down
3 changes: 3 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6474,6 +6474,9 @@ class TestTokenizer : public TestFixture {
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
Expand Down

0 comments on commit 7618e10

Please sign in to comment.