diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index aa4e14772..91e347e77 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -636,6 +636,13 @@ static bool iscpp11init_impl(const Token * const tok) return true; if (nameToken->str() == ">" && nameToken->link()) nameToken = nameToken->link()->previous(); + if (nameToken->str() == "]") { + const Token* newTok = nameToken->link()->previous(); + while (Token::Match(newTok, "%type%") && !newTok->isKeyword()) + newTok = newTok->previous(); + if (Token::simpleMatch(newTok, "new")) + return true; + } const Token *endtok = nullptr; if (Token::Match(nameToken, "%name%|return|: {") && diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 27e423de4..bc68b3205 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6046,6 +6046,7 @@ private: ASSERT_EQUALS("Aa*A{new=", testAst("A* a = new A{};")); ASSERT_EQUALS("Aa*A12,{new=", testAst("A* a = new A{ 1, 2 };")); ASSERT_EQUALS("Sv0[(new", testAst("new S(v[0]);")); // #10929 + ASSERT_EQUALS("SS::x(px0>intx[{newint1[{new:?(:", testAst("S::S(int x) : p(x > 0 ? new int[x]{} : new int[1]{}) {}")); // #10793 // placement new ASSERT_EQUALS("X12,3,(new ab,c,", testAst("new (a,b,c) X(1,2,3);"));