From 55b14853d0446d54a0650b0cb342fc80ac8614d2 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 29 Sep 2014 10:26:15 +0200 Subject: [PATCH] Fixed AST: Compile expression inside [] brackets of operator new. (#6193) --- lib/tokenlist.cpp | 4 +++- test/testtokenize.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 19ade2b4c..54bbb4bd1 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -662,11 +662,13 @@ static void compilePrecedence3(Token *&tok, AST_state& state) if (tok->str() == "(" && Token::Match(tok->link(), ") %type%")) tok = tok->link()->next(); state.op.push(tok); - while (Token::Match(tok, "%var%|*|&|<|[")) { + while (Token::Match(tok, "%var%|*|&|<")) { if (tok->link()) tok = tok->link(); tok = tok->next(); } + if (tok->str() == "[") + compilePrecedence2(tok, state); compileUnaryOp(tok2, state, nullptr); } else if (state.cpp && Token::Match(tok, "delete %var%|*|&|::|(|[")) { Token* tok2 = tok; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 58da939a2..68295950d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8352,7 +8352,7 @@ private: void astnewdelete() const { ASSERT_EQUALS("aintnew=", testAst("a = new int;")); - ASSERT_EQUALS("aintnew=", testAst("a = new int[4];")); + ASSERT_EQUALS("aint4[new=", testAst("a = new int[4];")); ASSERT_EQUALS("aFoonew=", testAst("a = new Foo(bar);")); ASSERT_EQUALS("aFoonew=", testAst("a = new Foo();")); ASSERT_EQUALS("Xnew", testAst("new (a,b,c) X(1,2,3);"));