PR c++/82070 - error with nested lambda capture
authorJason Merrill <jason@redhat.com>
Wed, 6 Sep 2017 19:36:48 +0000 (15:36 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 6 Sep 2017 19:36:48 +0000 (15:36 -0400)
* pt.c (tsubst_expr) [DECL_EXPR]: Register capture proxies with
register_local_specialization.

From-SVN: r251819

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested7.C [new file with mode: 0644]

index c1546308f7cc19b21a9622343b64af305c4745f0..e497094c4d50b46ab96f3f472ec5e862c5443e25 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-06  Jason Merrill  <jason@redhat.com>
+
+       PR c++/82070 - error with nested lambda capture
+       * pt.c (tsubst_expr) [DECL_EXPR]: Register capture proxies with
+       register_local_specialization.
+
 2017-09-06  Nathan Sidwell  <nathan@acm.org>
 
        * name-lookup.h (lookup_field_1): Delete.
index eb27f6a040286537bf2febff8872d7993bfee37e..4a65e31b6618e45039f340d4dee997129e8a0478 100644 (file)
@@ -15985,8 +15985,11 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
        else if (is_capture_proxy (decl)
                 && !DECL_TEMPLATE_INSTANTIATION (current_function_decl))
          {
-           /* We're in tsubst_lambda_expr, we've already inserted new capture
-              proxies, and uses will find them with lookup_name.  */
+           /* We're in tsubst_lambda_expr, we've already inserted a new
+              capture proxy, so look it up and register it.  */
+           tree inst = lookup_name (DECL_NAME (decl));
+           gcc_assert (inst != decl && is_capture_proxy (inst));
+           register_local_specialization (inst, decl);
            break;
          }
        else if (DECL_IMPLICIT_TYPEDEF_P (decl)
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested7.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested7.C
new file mode 100644 (file)
index 0000000..7403315
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/82070
+// { dg-do compile { target c++11 } }
+
+namespace a {
+template <typename b>
+void
+c (int, int, b d)
+{
+  [d] { [d] {}; };
+}
+}
+void
+e ()
+{
+  int f;
+  a::c (f, 3, [] {});
+}