AST: fixed ast for 'a(new A(1)), b(new B(2))'

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

View File

@ -659,15 +659,20 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
} else if (state.cpp && Token::Match(tok, "new %var%|::|(")) {
Token* newtok = tok;
tok = tok->next();
bool innertype = false;
if (tok->str() == "(") {
if (Token::Match(tok, "( &| %var%") && Token::Match(tok->link(), ") ( %type%") && Token::simpleMatch(tok->link()->linkAt(1), ") ("))
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();
else if (Token::Match(tok, "( &| %var%") && Token::simpleMatch(tok->link(), ") ("))
innertype = true;
}
else if (Token::Match(tok, "( &| %var%") && Token::simpleMatch(tok->link(), ") (")) {
tok = tok->next();
innertype = true;
}
}
state.op.push(tok);
while (Token::Match(tok, "%var%|*|&|<|::")) {
@ -682,7 +687,7 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
} else if (tok->str() == "[" || tok->str() == "(")
compilePrecedence2(tok, state);
compileUnaryOp(newtok, state, nullptr);
if (Token::simpleMatch(tok, ") ,"))
if (innertype && Token::simpleMatch(tok, ") ,"))
tok = tok->next();
} else if (state.cpp && Token::Match(tok, "delete %var%|*|&|::|(|[")) {
Token* tok2 = tok;

View File

@ -8394,6 +8394,7 @@ private:
ASSERT_EQUALS("adelete", testAst("delete[] a;"));
ASSERT_EQUALS("ab.3c-(delete", testAst("delete[] a.b(3 - c);"));
ASSERT_EQUALS("a::new=", testAst("a = new (b) ::X;"));
ASSERT_EQUALS("aA1(new(bB2(new(,", testAst("a(new A(1)), b(new B(2))"));
// clang testsuite..
ASSERT_EQUALS("const0(new", testAst("new const auto (0);"));