Do not add AST for pointer in variable declaration (#5593)

This commit is contained in:
Swasti Shrivastava 2023-10-31 14:56:03 +05:30 committed by GitHub
parent 12844703de
commit 7618e100b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -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%|*|&|<")) {

View File

@ -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