From ba0dca66d30a4e93a164a77e93c25c6f57877d6d 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 1/3] 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 d84cfde0dfac3e156c4c8bd32a9bcba45a96091e 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 2/3] add tests --- test/testtokenize.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7b2bee0d80e..f9c33b2f174 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("intab{&", testAst("int &a { b };")); + ASSERT_EQUALS("inta0{&&", testAst("int &&a { 0 };")); + ASSERT_EQUALS("intanullptr{*", testAst("int *a { nullptr };")); + } + #define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__) template bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) { From fe0c85119faf0be16d575fe34877fd923f3dd54e 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 3/3] fix --- lib/tokenlist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 5f48baea018..6a5a1984682 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% =") || Token::Match(typetok, "%var% {")) && typetok->varId()) tok = typetok; // Do not create AST for function declaration