The code that avoids all implicit capture in template contexts got
confused by fold_non_dependent_expr, which temporarily clears
processing_template_decl.  Fixed by using uses_template_parms instead,
which does not depend on the current value of
processing_template_decl.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 985b8e5fde47ac972db3e7b25c0ef25980bc0a05
Author: Jason Merrill <ja...@redhat.com>
Date:   Sat Sep 16 07:45:02 2017 -0400

            PR c++/82069
    
            * semantics.c (process_outer_var_ref): Check uses_template_parms
            instead of any_dependent_template_arguments_p.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 4f4c17f853d..3a3ae55aa44 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3347,8 +3347,7 @@ process_outer_var_ref (tree decl, tsubst_flags_t complain)
      time to implicitly capture.  */
   if (context == containing_function
       && DECL_TEMPLATE_INFO (containing_function)
-      && any_dependent_template_arguments_p (DECL_TI_ARGS
-                                            (containing_function)))
+      && uses_template_parms (DECL_TI_ARGS (containing_function)))
     return decl;
 
   /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template15.C 
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template15.C
new file mode 100644
index 00000000000..4da64f27fd8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template15.C
@@ -0,0 +1,11 @@
+// PR c++/82069
+// { dg-do compile { target c++11 } }
+
+struct A {
+  void foo(int *);
+};
+struct B : A {
+  template <typename> void bar(int *p1) {
+    [&] { foo(p1); };
+  }
+};

Reply via email to