diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index ccac6527a..0d1c77150 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1267,7 +1267,10 @@ static void compileAssignTernary(Token *&tok, AST_state& state) while (tok) { if (tok->isAssignmentOp()) { state.assign++; + const Token *tok1 = tok->next(); compileBinOp(tok, state, compileAssignTernary); + if (Token::simpleMatch(tok1, "{") && tok == tok1->link() && tok->next()) + tok = tok->next(); if (state.assign > 0) state.assign--; } else if (tok->str() == "?") { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b7c96861e..047143dbd 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6047,6 +6047,12 @@ private: 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};")); + + // #10334: Do not hang! + tokenizeAndStringify("void foo(const std::vector& locations = {\"\"}) {\n" + " for (int i = 0; i <= 123; ++i)\n" + " x->emplace_back(y);\n" + "}"); } void astbrackets() { // []