Skip to content

Commit 22e67d3

Browse files
authored
Fixed #10442 (AST: wrong ast of ({}) in struct initialization) (danmar#5135)
1 parent 6ea88c2 commit 22e67d3

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

lib/tokenlist.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,10 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
971971
else
972972
compileUnaryOp(tok, state, compileExpression);
973973
tok = tok2->link()->next();
974+
} else if (Token::simpleMatch(tok, "( {") && Token::simpleMatch(tok->linkAt(1)->previous(), "; } )") && !Token::Match(tok->previous(), "%name% (")) {
975+
state.op.push(tok->next());
976+
tok = tok->link()->next();
977+
continue;
974978
} else if (tok->str() == "(" && (!iscast(tok, state.cpp) || Token::Match(tok->previous(), "if|while|for|switch|catch"))) {
975979
Token* tok2 = tok;
976980
tok = tok->next();

test/testtokenize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6266,6 +6266,7 @@ class TestTokenizer : public TestFixture {
62666266
ASSERT_EQUALS("fori10=i{;;( i--", testAst("for (i=10;i;({i--;}) ) {}"));
62676267
ASSERT_EQUALS("c{1{,{2.3f{,(",
62686268
testAst("c({{}, {1}}, {2.3f});"));
6269+
ASSERT_EQUALS("x{{= e0= assert0(", testAst("x = {({ int e = 0; assert(0); e; })};"));
62696270

62706271
// function pointer
62716272
TODO_ASSERT_EQUALS("todo", "va_argapvoid((,(*0=", testAst("*va_arg(ap, void(**) ()) = 0;"));

0 commit comments

Comments
 (0)