From 8c63c8ced1a18ef071d155ea3d4bd797680dc4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 7 Nov 2023 20:48:56 +0100 Subject: [PATCH] Fix #12156 (AST: do not create AST for variable declaration 'bool& var') (#5631) --- lib/tokenlist.cpp | 5 +++++ test/testtokenize.cpp | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 7539538b5..a30ef0668 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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), ") [;,)]")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 78ae0a00c..0b753f571 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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