From e1cff1d1ef92f6a1c6962e0e4153b7353ccad04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 30 Jun 2021 21:40:45 +0200 Subject: [PATCH] Fixed #10334 (AST: hang with c++ initializer and emplace_back) --- lib/tokenlist.cpp | 3 +++ test/testtokenize.cpp | 6 ++++++ 2 files changed, 9 insertions(+) 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() { // []