We were forgetting to register capture proxies for new captures during
template instantiation.
Tested x86_64-pc-linux-gnu, applying to trunk and 5.
commit 6dbfe4dd24e6f001f17e8ea4cf1aa58f4b22ebc8
Author: Jason Merrill <ja...@redhat.com>
Date: Mon Aug 17 13:59:52 2015 -0400
PR c++/67244
* pt.c (tsubst_copy_and_build): Call insert_pending_capture_proxies.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index ecd86e4..b84bda4 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -16344,6 +16344,8 @@ tsubst_copy_and_build (tree t,
LAMBDA_EXPR_THIS_CAPTURE (r) = NULL_TREE;
+ insert_pending_capture_proxies ();
+
RETURN (build_lambda_object (r));
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested5.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested5.C
new file mode 100644
index 0000000..3ebdf3b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested5.C
@@ -0,0 +1,29 @@
+// PR c++/67244
+// { dg-do compile { target c++11 } }
+
+class A {
+public:
+ int operator*();
+};
+template <typename T, typename Predicate>
+void searchGen(int, int, T, Predicate p4) {
+ p4(0);
+}
+template <typename...> struct B;
+template <typename MetaFunction, typename Type, typename... Types>
+struct B<MetaFunction, Type, Types...> {
+ static void exec() { MetaFunction::template exec<Type>; }
+};
+template <typename MetaFunction, typename... Types> void forEachType() {
+ B<MetaFunction, Types...>::exec;
+}
+namespace {
+struct C {
+ template <typename T> void exec() {
+ A __trans_tmp_1;
+ const auto target = *__trans_tmp_1;
+ searchGen(0, 0, 0, [=](T) { [=] { target; }; });
+ }
+};
+}
+void ____C_A_T_C_H____T_E_S_T____75() { forEachType<C, int>; }