c++: generic lambda fn parm pack [PR104624]
authorJason Merrill <jason@redhat.com>
Thu, 21 Apr 2022 21:24:07 +0000 (17:24 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 26 Apr 2022 03:54:02 +0000 (23:54 -0400)
Parameter packs from the enclosing context can be used unexpanded in a
lambda that is itself part of a pack expansion, but not packs that are part
of the lambda itself.  We already check for capture packs; we also need to
check for function parameter packs of the lambda call operator.

PR c++/104624

gcc/cp/ChangeLog:

* pt.cc (check_for_bare_parameter_packs): Check for lambda
function parameter pack.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/lambda-generic-variadic22.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic22.C [new file with mode: 0644]

index 7dd9e67..a77b316 100644 (file)
@@ -4341,7 +4341,9 @@ check_for_bare_parameter_packs (tree t, location_t loc /* = UNKNOWN_LOCATION */)
         parameter_packs = TREE_CHAIN (parameter_packs))
       {
        tree pack = TREE_VALUE (parameter_packs);
-       if (is_capture_proxy (pack))
+       if (is_capture_proxy (pack)
+           || (TREE_CODE (pack) == PARM_DECL
+               && DECL_CONTEXT (DECL_CONTEXT (pack)) == lam))
          break;
       }
 
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic22.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic22.C
new file mode 100644 (file)
index 0000000..670c598
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/104624
+// { dg-do compile { target c++14 } }
+
+template <typename T>
+auto f (T)
+{
+  auto a = [](auto ... i)      // { dg-prune-output "incomplete type" }
+  {
+    int x[][i] = { 0 };                // { dg-error "not expanded" }
+  }();
+}
+void g ()
+{
+  f(0);
+}