diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index a77b3166818..3cf1d7af8d2 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -12682,7 +12682,13 @@ gen_elem_of_pack_expansion_instantiation (tree pattern, t = tsubst_expr (pattern, args, complain, in_decl, /*integral_constant_expression_p=*/false); else - t = tsubst (pattern, args, complain, in_decl); + { + t = tsubst (pattern, args, complain, in_decl); + if (is_auto (t) && !ith_elem_is_expansion) + /* When expanding the fake auto... pack expansion from add_capture, we + need to mark that the expansion is no longer a pack. */ + TEMPLATE_TYPE_PARAMETER_PACK (t) = false; + } /* If the Ith argument pack element is a pack expansion, then the Ith element resulting from the substituting is going to diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C b/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C new file mode 100644 index 00000000000..f3c3899e97a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C @@ -0,0 +1,18 @@ +// PR c++/102629 +// { dg-do compile { target c++20 } } + +template T&& forward(T&); +template T&& forward(T&&); + +struct S {}; + +template +void foo(Args&&... args) { + [...args = forward /*(args)*/] { // { dg-error "" } + [](auto...) { } (forward(args)...); + }; +} + +void bar( ) { + foo(S{}); +}