]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: nested lambda capture pack [PR119345]
authorJason Merrill <jason@redhat.com>
Thu, 10 Apr 2025 18:34:35 +0000 (14:34 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 10 Apr 2025 20:42:34 +0000 (16:42 -0400)
tsubst_stmt already registers a local capture proxy as a
local_specialization of both an outer capture proxy and the captured
variable; we also need to do that in add_extra_args.

PR c++/119345

gcc/cp/ChangeLog:

* pt.cc (add_extra_args): Also register a specialization
of the captured variable.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-targ14.C: New test.

(cherry picked from commit 5957b9919c9ecda6e4ca198086f8bb9ea215232c)

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

index 3a5ffd8b683ed8ac4f716320a4bbda4d420b74c7..a4028a545a3376609387a13b60979504bd8cb160 100644 (file)
@@ -13520,6 +13520,8 @@ add_extra_args (tree extra, tree args, tsubst_flags_t complain, tree in_decl)
              inst = local;
          /* else inst is already a full instantiation of the pack.  */
          register_local_specialization (inst, gen);
+         if (is_normal_capture_proxy (gen))
+           register_local_specialization (inst, DECL_CAPTURED_VARIABLE (gen));
        }
       gcc_assert (!TREE_PURPOSE (extra));
       extra = TREE_VALUE (extra);
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ14.C b/gcc/testsuite/g++.dg/cpp2a/lambda-targ14.C
new file mode 100644 (file)
index 0000000..debb15e
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/119345
+// { dg-do compile { target c++20 } }
+
+void f(auto... args) {
+  [args...]<int... i> {
+    (..., [args...] { i; });
+  }.template operator()<0>();
+}
+
+int main() {
+  f();
+}