diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 8fef5842f..0feaf01e8 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -709,6 +709,16 @@ static void compileTerm(Token *&tok, AST_state& state) compileBinOp(tok, state, compileExpression); if (Token::Match(tok, "} ,|:")) tok = tok->next(); + } else if (state.cpp && Token::Match(tok->tokAt(-2), "%name% ( {")) { + if (Token::simpleMatch(tok, "{ }")) + tok = tok->tokAt(2); + else { + Token *tok1 = tok; + state.inArrayAssignment++; + compileUnaryOp(tok, state, compileExpression); + state.inArrayAssignment--; + tok = tok1->link()->next(); + } } else if (!state.inArrayAssignment && !Token::simpleMatch(prev, "=")) { state.op.push(tok); tok = tok->link()->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index eca553124..66d90d801 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7441,12 +7441,12 @@ private: // ({..}) ASSERT_EQUALS("a{+d+ bc+", testAst("a+({b+c;})+d")); ASSERT_EQUALS("a{d*+ bc+", testAst("a+({b+c;})*d")); - ASSERT_EQUALS("xa{((= bc( yd{((= ef(", + ASSERT_EQUALS("xabc({((= ydef({((=", testAst("x=(int)(a({b(c);}));" // don't hang "y=(int)(d({e(f);}));")); - ASSERT_EQUALS("QT_WA{{,( x0= QT_WA{{,( x1= x2=", - testAst("QT_WA({},{x=0;});" // don't hang - "QT_WA({x=1;},{x=2;});")); + ASSERT_EQUALS("A{,( x0= Bx1={{,( x2=", // TODO: This is not perfect!! + testAst("A({},{x=0;});" // don't hang + "B({x=1;},{x=2;});")); ASSERT_EQUALS("xMACROtype.T=value.1=,{({=", testAst("x = { MACRO( { .type=T, .value=1 } ) }")); // don't hang: MACRO({..}) ASSERT_EQUALS("fori10=i{;;( i--", testAst("for (i=10;i;({i--;}) ) {}")); @@ -7486,6 +7486,7 @@ private: ASSERT_EQUALS("Abc({newreturn", testAst("return new A {b(c)};")); ASSERT_EQUALS("a{{return", testAst("return{{a}};")); ASSERT_EQUALS("a{b{,{return", testAst("return{{a},{b}};")); + ASSERT_EQUALS("abc{d{,{(=", testAst("a = b({ c{}, d{} });")); } void astbrackets() { // []