diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 71dfeab39..a52c02e27 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -657,10 +657,12 @@ static void compilePrecedence3(Token *&tok, AST_state& state) compilePrecedence3(tok, state); compileUnaryOp(tok2, state, nullptr); } else if (state.cpp && Token::Match(tok, "new %var%|::|(")) { - Token* tok2 = tok; + 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(); state.op.push(tok); while (Token::Match(tok, "%var%|*|&|<")) { if (tok->link()) @@ -673,7 +675,7 @@ static void compilePrecedence3(Token *&tok, AST_state& state) compileBinOp(tok, state, compilePrecedence2); } else if (tok->str() == "[" || tok->str() == "(") compilePrecedence2(tok, state); - compileUnaryOp(tok2, state, nullptr); + compileUnaryOp(newtok, state, nullptr); } else if (state.cpp && Token::Match(tok, "delete %var%|*|&|::|(|[")) { Token* tok2 = tok; tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index be10d1d4d..84bb26bdf 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8382,6 +8382,7 @@ private: // clang testsuite.. ASSERT_EQUALS("const0(new", testAst("new const auto (0);")); ASSERT_EQUALS("auto0.0(new", testAst("new (auto) (0.0);")); + ASSERT_EQUALS("intnew", testAst("new (int S::*[3][4][5]) ();")); } void astpar() const { // parentheses