Fixed #10334 (AST: hang with c++ initializer and emplace_back)

This commit is contained in:
Daniel Marjamäki 2021-06-30 21:40:45 +02:00
parent e50f7a3e09
commit e1cff1d1ef
2 changed files with 9 additions and 0 deletions

View File

@ -1267,7 +1267,10 @@ static void compileAssignTernary(Token *&tok, AST_state& state)
while (tok) { while (tok) {
if (tok->isAssignmentOp()) { if (tok->isAssignmentOp()) {
state.assign++; state.assign++;
const Token *tok1 = tok->next();
compileBinOp(tok, state, compileAssignTernary); compileBinOp(tok, state, compileAssignTernary);
if (Token::simpleMatch(tok1, "{") && tok == tok1->link() && tok->next())
tok = tok->next();
if (state.assign > 0) if (state.assign > 0)
state.assign--; state.assign--;
} else if (tok->str() == "?") { } else if (tok->str() == "?") {

View File

@ -6047,6 +6047,12 @@ private:
ASSERT_EQUALS("decltypex({", testAst("decltype(x){};")); ASSERT_EQUALS("decltypex({", testAst("decltype(x){};"));
ASSERT_EQUALS("decltypexy+(yx+(", testAst("decltype(x+y)(y+x);")); ASSERT_EQUALS("decltypexy+(yx+(", testAst("decltype(x+y)(y+x);"));
ASSERT_EQUALS("decltypexy+(yx+{", testAst("decltype(x+y){y+x};")); ASSERT_EQUALS("decltypexy+(yx+{", testAst("decltype(x+y){y+x};"));
// #10334: Do not hang!
tokenizeAndStringify("void foo(const std::vector<std::string>& locations = {\"\"}) {\n"
" for (int i = 0; i <= 123; ++i)\n"
" x->emplace_back(y);\n"
"}");
} }
void astbrackets() { // [] void astbrackets() { // []