From 3ff8ce316ca23635238c2ae8405f0c616bc86859 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 7 Jun 2023 20:46:14 +0200 Subject: [PATCH] Fix AST for parameter pack (#10199, #10492, #11103) (#5125) * Fix AST for parameter pack (#10199, #10492, #11103) * Skip ... after ) --- lib/tokenlist.cpp | 3 ++- test/testtokenize.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 04eb4fae2..d55d75c55 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -897,7 +897,8 @@ static void compilePrecedence2(Token *&tok, AST_state& state) if (tok->tokType() == Token::eIncDecOp && !isPrefixUnary(tok, state.cpp)) { compileUnaryOp(tok, state, compileScope); } else if (tok->str() == "...") { - state.op.push(tok); + if (!Token::simpleMatch(tok->previous(), ")")) + state.op.push(tok); tok = tok->next(); break; } else if (tok->str() == "." && tok->strAt(1) != "*") { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index db83f947e..a6f5025ad 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6465,6 +6465,24 @@ private: ASSERT_EQUALS("xfts(=", testAst("; auto x = f(ts...);")); + ASSERT_EQUALS("da((new= ifd(", testAst("template \n" // #10199 + "void c(b... e) {\n" + " a d = new a((e)...);\n" + " if (d) {}\n" + "}\n")); + + ASSERT_EQUALS("ad*astdforward::e((new= ifd(", testAst("struct a {};\n" // #11103 + "template void c(b... e) {\n" + " a* d = new a(std::forward(e)...);\n" + " if (d) {}\n" + "}\n")); + + ASSERT_EQUALS("stddir::Args...&&, dir\"abc\"+= dirconcatstdforward::args((+return", + testAst("template std::string concat(std::string dir, Args&& ...args) {\n" // #10492 + " dir += \"abc\";\n" + " return dir + concat(std::forward(args)...);\n" + "}\n")); + // #11369 ASSERT_NO_THROW(tokenizeAndStringify("int a;\n" "template auto b() -> decltype(a) {\n"