Skip to content

Commit

Permalink
Fix #12156 (AST: do not create AST for variable declaration 'bool& va…
Browse files Browse the repository at this point in the history
…r') (#5631)
  • Loading branch information
danmar committed Nov 7, 2023
1 parent 8788657 commit 8c63c8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,8 +1454,11 @@ static Token * createAstAtToken(Token *tok, bool cpp)
return tok2;
}
if (Token::Match(tok, "%type%") && !Token::Match(tok, "return|throw|if|while|new|delete")) {
bool isStandardTypeOrQualifier = false;
Token* type = tok;
while (Token::Match(type, "%type%|*|&|<")) {
if (type->isName() && (type->isStandardType() || Token::Match(type, "const|mutable|static|volatile")))
isStandardTypeOrQualifier = true;
if (type->str() == "<") {
if (type->link())
type = type->link();
Expand All @@ -1464,6 +1467,8 @@ static Token * createAstAtToken(Token *tok, bool cpp)
}
type = type->next();
}
if (isStandardTypeOrQualifier && Token::Match(type, "%var% [;,)]"))
return type;
if (Token::Match(type, "( * *| %var%") &&
Token::Match(type->link()->previous(), "%var%|] ) (") &&
Token::Match(type->link()->linkAt(1), ") [;,)]"))
Expand Down
1 change: 1 addition & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6483,6 +6483,7 @@ class TestTokenizer : public TestFixture {

ASSERT_EQUALS("", testAst("void f(enum E* var){}"));
ASSERT_EQUALS("", testAst("void f(enum E*& var){}"));
ASSERT_EQUALS("", testAst("void f(bool& var){}"));
}

void astunaryop() const { // unary operators
Expand Down

0 comments on commit 8c63c8c

Please sign in to comment.