https://gcc.gnu.org/g:779e002a1dc4ee7c688b7fb497375185cbcfec87

commit r14-11593-g779e002a1dc4ee7c688b7fb497375185cbcfec87
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Apr 10 14:34:35 2025 -0400

    c++: nested lambda capture pack [PR119345]
    
    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)

Diff:
---
 gcc/cp/pt.cc                               |  2 ++
 gcc/testsuite/g++.dg/cpp2a/lambda-targ14.C | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 3a5ffd8b683e..a4028a545a33 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -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
index 000000000000..debb15e83f61
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ14.C
@@ -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();
+}

Reply via email to