From be36539ad7578c1c0ba4f20457d245c9322a8698 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 6 Nov 2015 17:34:26 +0100 Subject: [PATCH] Fixed AST generation for C++11-style initialization (#6528) --- lib/tokenlist.cpp | 6 ++++-- test/testtokenize.cpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 78a403660..1cb0f14be 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -576,7 +576,9 @@ static void compileTerm(Token *&tok, AST_state& state) } } } else if (tok->str() == "{") { - if (!state.inArrayAssignment && tok->strAt(-1) != "=") { + if (tok->previous() && tok->previous()->isName()) { + compileBinOp(tok, state, compileExpression); + } else if (!state.inArrayAssignment && tok->strAt(-1) != "=") { state.op.push(tok); tok = tok->link()->next(); } else { @@ -746,7 +748,7 @@ static void compilePrecedence3(Token *&tok, AST_state& state) state.op.push(tok->next()); tok = tok->link()->next(); compileBinOp(tok, state, compilePrecedence2); - } else if (tok && (tok->str() == "[" || tok->str() == "(")) + } else if (tok && (tok->str() == "[" || tok->str() == "(" || tok->str() == "{")) compilePrecedence2(tok, state); else if (innertype && Token::simpleMatch(tok, ") [")) { tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index bdb85d728..0d4c2c126 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8237,6 +8237,7 @@ private: ASSERT_EQUALS("abc{d:?=", testAst("a=b?c{}:d;")); ASSERT_EQUALS("abc12,{d:?=", testAst("a=b?c{1,2}:d;")); ASSERT_EQUALS("a::12,{", testAst("::a{1,2};")); // operator precedence + ASSERT_EQUALS("Abc({newreturn", testAst("return new A {b(c)};")); } void astbrackets() { // []