From 4783a67042254c8412ead61357e46476adcd16a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 11 Oct 2014 11:27:13 +0200 Subject: [PATCH] AST: fixes for more new statements from clang test suite --- lib/tokenlist.cpp | 12 ++++++++---- test/testtokenize.cpp | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index a52c02e27..fed2e2f20 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -659,10 +659,14 @@ static void compilePrecedence3(Token *&tok, AST_state& state) } else if (state.cpp && Token::Match(tok, "new %var%|::|(")) { Token* newtok = tok; tok = tok->next(); - if (tok->str() == "(" && Token::Match(tok->link(), ") %type%")) - tok = tok->link()->next(); - else if (Token::Match(tok, "( %type%") && Token::simpleMatch(tok->link(), ") ( )")) - tok = tok->next(); + if (tok->str() == "(") { + if (Token::Match(tok, "( %var% ) ( %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(), ") [(;]")) + tok = tok->next(); + } state.op.push(tok); while (Token::Match(tok, "%var%|*|&|<")) { if (tok->link()) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2d20e79fb..d29a878be 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8387,8 +8387,10 @@ private: // clang testsuite.. ASSERT_EQUALS("const0(new", testAst("new const auto (0);")); - ASSERT_EQUALS("auto0.0(new", testAst("new (auto) (0.0);")); + ASSERT_EQUALS("autonew", testAst("new (auto) (0.0);")); ASSERT_EQUALS("intnew", testAst("new (int S::*[3][4][5]) ();")); + ASSERT_EQUALS("pSnew=", testAst("p=new (x)(S)(1,2);")); + ASSERT_EQUALS("inti[new(", testAst("(void)new (int[i]);")); } void astpar() const { // parentheses