Fix #12156 (AST: do not create AST for variable declaration 'bool& var') (#5631)

This commit is contained in:
Daniel Marjamäki 2023-11-07 20:48:56 +01:00 committed by GitHub
parent 87886576fc
commit 8c63c8ced1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -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();
@ -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), ") [;,)]"))

View File

@ -6483,6 +6483,7 @@ private:
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