if (!processing_template_decl || !t || t == error_mark_node)
return false;
- /* A lambda might use a parameter pack from the containing context. */
- if (current_class_type && LAMBDA_TYPE_P (current_class_type)
- && CLASSTYPE_TEMPLATE_INFO (current_class_type))
- return false;
-
if (TREE_CODE (t) == TYPE_DECL)
t = TREE_TYPE (t);
cp_walk_tree (&t, &find_parameter_packs_r, &ppd, ppd.visited);
delete ppd.visited;
+ /* It's OK for a lambda to have an unexpanded parameter pack from the
+ containing context, but do complain about unexpanded capture packs. */
+ if (current_class_type && LAMBDA_TYPE_P (current_class_type)
+ && CLASSTYPE_TEMPLATE_INFO (current_class_type))
+ for (; parameter_packs;
+ parameter_packs = TREE_CHAIN (parameter_packs))
+ {
+ tree pack = TREE_VALUE (parameter_packs);
+ if (is_capture_proxy (pack))
+ break;
+ }
+
if (parameter_packs)
{
if (loc == UNKNOWN_LOCATION)
--- /dev/null
+// PR c++/97358
+// { dg-do compile { target c++11 } }
+
+template <typename... T> void foo (T... x) {}
+
+template <typename... T> void bar (T... x)
+{
+ foo ([x...] { return x; }...); // { dg-error "not expanded|no parameter packs" }
+#if __cpp_init_captures >= 201803L
+ foo ([...y = x] { return y; }...); // { dg-error "not expanded|no parameter packs" "" { target c++20 } }
+#endif
+}
+
+void
+test ()
+{
+ bar ();
+ bar (1);
+ bar (2.0, 3LL, 4);
+}