From 7ab50e17943ee4caaf2fba2d4238a00e0409f1e7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 6 Sep 2017 15:36:48 -0400 Subject: [PATCH] PR c++/82070 - error with nested lambda capture * pt.c (tsubst_expr) [DECL_EXPR]: Register capture proxies with register_local_specialization. From-SVN: r251819 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 7 +++++-- .../g++.dg/cpp0x/lambda/lambda-nested7.C | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested7.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c1546308f7c..e497094c4d5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-09-06 Jason Merrill + + 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 * name-lookup.h (lookup_field_1): Delete. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index eb27f6a0402..4a65e31b661 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 index 00000000000..74033150f51 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested7.C @@ -0,0 +1,17 @@ +// PR c++/82070 +// { dg-do compile { target c++11 } } + +namespace a { +template +void +c (int, int, b d) +{ + [d] { [d] {}; }; +} +} +void +e () +{ + int f; + a::c (f, 3, [] {}); +} -- 2.30.2