From 955d6d8fc60af2506e71fc152265cfd48c240299 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 3 Apr 2022 20:05:03 +0200 Subject: [PATCH] Fix #10793 internalAstError with brace-init in ternary (#3966) * Fix #10793 internalAstError with brace-init in ternary * Undo --- lib/tokenlist.cpp | 7 +++++++ test/testtokenize.cpp | 1 + 2 files changed, 8 insertions(+) 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);"));