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