AST: fixed ast for 'new (char *)[10]'

This commit is contained in:
Daniel Marjamäki 2014-10-12 12:57:01 +02:00
parent f72a8d3f15
commit aac9e66147
2 changed files with 9 additions and 3 deletions

View File

@ -665,11 +665,10 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
tok = tok->link()->next();
if (Token::Match(tok->link(), ") ::| %type%"))
tok = tok->link()->next();
else if (Token::Match(tok, "( %type%") && Token::Match(tok->link(), ") [();,]")) {
else if (Token::Match(tok, "( %type%") && Token::Match(tok->link(), ") [();,[]")) {
tok = tok->next();
innertype = true;
}
else if (Token::Match(tok, "( &| %var%") && Token::simpleMatch(tok->link(), ") (")) {
} else if (Token::Match(tok, "( &| %var%") && Token::simpleMatch(tok->link(), ") (")) {
tok = tok->next();
innertype = true;
}
@ -686,6 +685,10 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
compileBinOp(tok, state, compilePrecedence2);
} else if (tok->str() == "[" || tok->str() == "(")
compilePrecedence2(tok, state);
else if (innertype && Token::simpleMatch(tok, ") [")) {
tok = tok->next();
compilePrecedence2(tok, state);
}
compileUnaryOp(newtok, state, nullptr);
if (innertype && Token::simpleMatch(tok, ") ,"))
tok = tok->next();

View File

@ -8405,6 +8405,9 @@ private:
ASSERT_EQUALS("intp* pnew malloc4(", testAst("int*p; new (p) (malloc(4));"));
ASSERT_EQUALS("intnew", testAst("new (&w.x)(int*)(0);"));
ASSERT_EQUALS("&new", testAst("new (&w.x)(0);")); // <- the "(int*)" has been simplified
// gcc testsuite..
ASSERT_EQUALS("char10[new(", testAst("(void)new(char*)[10];"));
}
void astpar() const { // parentheses