From f72a8d3f15ea22114140347176903ac1c7deb355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 12 Oct 2014 12:13:01 +0200 Subject: [PATCH] AST: fixed ast for 'a(new A(1)), b(new B(2))' --- lib/tokenlist.cpp | 11 ++++++++--- test/testtokenize.cpp | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 1fe2b4364..bdc913733 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 157e8992c..518dbddeb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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);"));