From ce0ce7cd6d3eabe4d0462209b90ad521af8f2ef0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 31 Mar 2026 13:52:06 +0200 Subject: [PATCH 1/3] Update testtokenize.cpp --- test/testtokenize.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f7437cdf2e4..4287cf4eb22 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -437,6 +437,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(astenumdecl); TEST_CASE(astcompound); TEST_CASE(astfuncdecl); + TEST_CASE(astarrayinit); TEST_CASE(startOfExecutableScope); @@ -7492,6 +7493,11 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("", testAst("::int32_t f();")); } + void astarrayinit() { // #11738 + ASSERT_EQUALS("a2[12,{", testAst("int a[2]{ 1, 2 };")); + ASSERT_EQUALS("a2[2[ 12, 34,{", testAst("int a[2][2]{ { 1, 2 }, { 3, 4 } };")); + } + #define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__) template bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) { @@ -8641,6 +8647,10 @@ class TestTokenizer : public TestFixture { "{ 1", Token::Cpp11init::CPP11INIT); + testIsCpp11init("int a[2]{ 1, 2 }; \n", + "{ 1", + Token::Cpp11init::CPP11INIT); + ASSERT_NO_THROW(tokenizeAndStringify("template struct X {};\n" // don't crash "template auto f(T t) -> X {}\n")); ASSERT_EQUALS("[test.cpp:2:22]: (debug) auto token with no type. [autoNoType]\n", errout_str()); From 99ee7db398fd8ebcfa016dd3b1c71c3980bf21d1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 31 Mar 2026 13:52:46 +0200 Subject: [PATCH 2/3] Update testastutils.cpp --- test/testastutils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/testastutils.cpp b/test/testastutils.cpp index 8ca2412a095..eb9559ed39d 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -81,8 +81,8 @@ class TestAstUtils : public TestFixture { ASSERT_EQUALS(true, findLambdaEndToken("[](void) mutable -> const * int { return x; }")); ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const ** int { return x; }")); ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const * const* int { return x; }")); - ASSERT_EQUALS(false, findLambdaEndToken("int** a[] { new int*[2] { new int, new int} }", "[ ]")); - ASSERT_EQUALS(false, findLambdaEndToken("int** a[] { new int*[2] { new int, new int} }", "[ 2")); + ASSERT_EQUALS(false, findLambdaEndToken("int** a[] { new int*[2] { new int, new int} };", "[ ]")); + ASSERT_EQUALS(false, findLambdaEndToken("int** a[] { new int*[2] { new int, new int} };", "[ 2")); ASSERT_EQUALS(false, findLambdaEndToken("shared_ptr sp{ new Type *[2] {new Type, new Type}, Deleter{ 2 } };", "[ 2")); ASSERT_EQUALS(true, findLambdaEndToken("int i = 5 * []{ return 7; }();", "[", /*checkNext*/ false)); } From 5de127e12734bb2e338ea395f401967f40c0b42d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 31 Mar 2026 13:55:09 +0200 Subject: [PATCH 3/3] Update tokenlist.cpp --- lib/tokenlist.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 55ca98c628c..3df17141f24 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -589,10 +589,16 @@ static bool iscpp11init_impl(const Token * const tok) if (nameToken->str() == ">" && nameToken->link()) nameToken = nameToken->link()->previous(); if (Token::Match(nameToken, "]|*")) { - const Token* newTok = nameToken->link() ? nameToken->link()->previous() : nameToken->previous(); - while (Token::Match(newTok, "%type%|::|*") && !newTok->isKeyword()) - newTok = newTok->previous(); - if (Token::simpleMatch(newTok, "new")) + const Token* tok2 = nameToken; + if (tok2->link()) { + while (tok2 && tok2->link()) + tok2 = tok2->link()->previous(); + } + else + tok2 = tok2->previous(); + while (Token::Match(tok2, "%type%|::|*") && !tok2->isKeyword()) + tok2 = tok2->previous(); + if (Token::Match(tok2, "new|%var%")) return true; }