Fix #10793 internalAstError with brace-init in ternary (#3966)

* Fix #10793 internalAstError with brace-init in ternary

* Undo
This commit is contained in:
chrchr-github 2022-04-03 20:05:03 +02:00 committed by GitHub
parent 39265f8ce0
commit 955d6d8fc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -636,6 +636,13 @@ static bool iscpp11init_impl(const Token * const tok)
return true; return true;
if (nameToken->str() == ">" && nameToken->link()) if (nameToken->str() == ">" && nameToken->link())
nameToken = nameToken->link()->previous(); 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; const Token *endtok = nullptr;
if (Token::Match(nameToken, "%name%|return|: {") && if (Token::Match(nameToken, "%name%|return|: {") &&

View File

@ -6046,6 +6046,7 @@ private:
ASSERT_EQUALS("Aa*A{new=", testAst("A* a = new A{};")); ASSERT_EQUALS("Aa*A{new=", testAst("A* a = new A{};"));
ASSERT_EQUALS("Aa*A12,{new=", testAst("A* a = new A{ 1, 2 };")); ASSERT_EQUALS("Aa*A12,{new=", testAst("A* a = new A{ 1, 2 };"));
ASSERT_EQUALS("Sv0[(new", testAst("new S(v[0]);")); // #10929 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 // placement new
ASSERT_EQUALS("X12,3,(new ab,c,", testAst("new (a,b,c) X(1,2,3);")); ASSERT_EQUALS("X12,3,(new ab,c,", testAst("new (a,b,c) X(1,2,3);"));