Skip to content

Commit aac9e66

Browse files
committed
AST: fixed ast for 'new (char *)[10]'
1 parent f72a8d3 commit aac9e66

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/tokenlist.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,10 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
665665
tok = tok->link()->next();
666666
if (Token::Match(tok->link(), ") ::| %type%"))
667667
tok = tok->link()->next();
668-
else if (Token::Match(tok, "( %type%") && Token::Match(tok->link(), ") [();,]")) {
668+
else if (Token::Match(tok, "( %type%") && Token::Match(tok->link(), ") [();,[]")) {
669669
tok = tok->next();
670670
innertype = true;
671-
}
672-
else if (Token::Match(tok, "( &| %var%") && Token::simpleMatch(tok->link(), ") (")) {
671+
} else if (Token::Match(tok, "( &| %var%") && Token::simpleMatch(tok->link(), ") (")) {
673672
tok = tok->next();
674673
innertype = true;
675674
}
@@ -686,6 +685,10 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
686685
compileBinOp(tok, state, compilePrecedence2);
687686
} else if (tok->str() == "[" || tok->str() == "(")
688687
compilePrecedence2(tok, state);
688+
else if (innertype && Token::simpleMatch(tok, ") [")) {
689+
tok = tok->next();
690+
compilePrecedence2(tok, state);
691+
}
689692
compileUnaryOp(newtok, state, nullptr);
690693
if (innertype && Token::simpleMatch(tok, ") ,"))
691694
tok = tok->next();

test/testtokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8405,6 +8405,9 @@ class TestTokenizer : public TestFixture {
84058405
ASSERT_EQUALS("intp* pnew malloc4(", testAst("int*p; new (p) (malloc(4));"));
84068406
ASSERT_EQUALS("intnew", testAst("new (&w.x)(int*)(0);"));
84078407
ASSERT_EQUALS("&new", testAst("new (&w.x)(0);")); // <- the "(int*)" has been simplified
8408+
8409+
// gcc testsuite..
8410+
ASSERT_EQUALS("char10[new(", testAst("(void)new(char*)[10];"));
84088411
}
84098412

84108413
void astpar() const { // parentheses

0 commit comments

Comments
 (0)