From 19e45cb6f0395a79e4d567154293b74a1f64d929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Tue, 12 May 2026 15:38:04 +0200 Subject: [PATCH 1/4] don't create ast twice if using full simplification in testAst --- test/testtokenize.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7b2bee0d80e..9b751eaf061 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6522,21 +6522,21 @@ class TestTokenizer : public TestFixture { tokenizer.createLinks2(); tokenizer.simplifyCAlternativeTokens(); tokenizer.list.front()->assignIndexes(); - } else { // Full - tokenizer.simplifyTokens1(""); - } - // set varid.. - for (Token *tok = tokenizer.list.front(); tok; tok = tok->next()) { - if (tok->str() == "var") - tok->varId(1); - } + // set varid.. + for (Token *tok = tokenizer.list.front(); tok; tok = tok->next()) { + if (tok->str() == "var") + tok->varId(1); + } - // Create AST.. - tokenizer.prepareTernaryOpForAST(); - tokenizer.list.createAst(); + // Create AST.. + tokenizer.prepareTernaryOpForAST(); + tokenizer.list.createAst(); - tokenizer.list.validateAst(false); + tokenizer.list.validateAst(false); + } else { // Full + tokenizer.simplifyTokens1(""); + } // Basic AST validation for (const Token *tok = tokenizer.list.front(); tok; tok = tok->next()) { From 7e5a9ca66858137323368ab6cafa8717d0024615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 11 May 2026 15:37:20 +0200 Subject: [PATCH 2/4] update invalidContainer check --- lib/checkstl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index faa6f25911d..5857dfbb4a8 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1193,8 +1193,7 @@ void CheckStl::invalidContainer() if (info.tok->variable()->isReference() && !isVariableDecl(info.tok) && reaches(info.tok->variable()->nameToken(), tok, nullptr)) { - if ((assignExpr && Token::Match(assignExpr->astOperand1(), "& %varid%", info.tok->varId())) || // TODO: fix AST - Token::Match(assignExpr, "& %varid% {|(", info.tok->varId())) { + if ((assignExpr && Token::Match(assignExpr->astOperand1()->previous(), "& %varid%", info.tok->varId()))) { return false; } From 777345371a10add4ba87b3422a4800ea1c81ffb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 11 May 2026 15:50:19 +0200 Subject: [PATCH 3/4] add tests --- test/testtokenize.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 9b751eaf061..b6f84e1ec56 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -439,6 +439,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(astcompound); TEST_CASE(astfuncdecl); TEST_CASE(astarrayinit); + TEST_CASE(astbracedinit); TEST_CASE(startOfExecutableScope); @@ -7535,6 +7536,12 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("a2[2[ 12, 34,{", testAst("int a[2][2]{ { 1, 2 }, { 3, 4 } };")); } + void astbracedinit() { + ASSERT_EQUALS("ab{", testAst("int &a { b };", AstStyle::Simple, ListSimplification::Full)); + ASSERT_EQUALS("a0{", testAst("int &&a { 0 };", AstStyle::Simple, ListSimplification::Full)); + ASSERT_EQUALS("anullptr{", testAst("int *a { nullptr };", AstStyle::Simple, ListSimplification::Full)); + } + #define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__) template bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) { From 716451629ec98a1857e8d7e9ecc304c1f19c7a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 11 May 2026 15:22:47 +0200 Subject: [PATCH 4/4] fix --- lib/tokenlist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 5f48baea018..cd21a8fe41c 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1817,7 +1817,7 @@ static Token * createAstAtToken(Token *tok) } typetok = typetok->next(); } - if (Token::Match(typetok, "%var% =") && typetok->varId()) + if (Token::Match(typetok, "%var% [={]")) tok = typetok; // Do not create AST for function declaration