Fix AST for parameter pack (#10199, #10492, #11103) (#5125)

* Fix AST for parameter pack (#10199, #10492, #11103)

* Skip ... after )
This commit is contained in:
chrchr-github 2023-06-07 20:46:14 +02:00 committed by GitHub
parent ec4267a2bd
commit 3ff8ce316c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -897,6 +897,7 @@ 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() == "...") {
if (!Token::simpleMatch(tok->previous(), ")"))
state.op.push(tok);
tok = tok->next();
break;

View File

@ -6465,6 +6465,24 @@ private:
ASSERT_EQUALS("xfts(=", testAst("; auto x = f(ts...);"));
ASSERT_EQUALS("da((new= ifd(", testAst("template <typename a, typename... b>\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 <class... b> void c(b... e) {\n"
" a* d = new a(std::forward<b>(e)...);\n"
" if (d) {}\n"
"}\n"));
ASSERT_EQUALS("stddir::Args...&&, dir\"abc\"+= dirconcatstdforward::args((+return",
testAst("template <typename ...Args> std::string concat(std::string dir, Args&& ...args) {\n" // #10492
" dir += \"abc\";\n"
" return dir + concat(std::forward<Args>(args)...);\n"
"}\n"));
// #11369
ASSERT_NO_THROW(tokenizeAndStringify("int a;\n"
"template <class> auto b() -> decltype(a) {\n"