]> gcc.gnu.org Git - gcc.git/commitdiff
[PR c++/86610] lambda captures in templates
authorNathan Sidwell <nathan@acm.org>
Thu, 17 Jan 2019 11:56:58 +0000 (11:56 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 17 Jan 2019 11:56:58 +0000 (11:56 +0000)
https://gcc.gnu.org/ml/gcc-patches/2019-01/msg00948.html
PR c++/86610
* semantics.c (process_outer_var_ref): Only skip dependent types
in templates.

PR c++/86610
* g++.dg/cpp0x/pr86610.C: New.

From-SVN: r268016

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr86610.C [new file with mode: 0644]

index 524fbd366c030b769cec1baebad2c7fb034beb4e..dec8d64d46f118fc34829f63fb2e1b22533d99d8 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-17  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/86610
+       * semantics.c (process_outer_var_ref): Only skip dependent types
+       in templates.
+
 2019-01-17  Alexandre Oliva <aoliva@redhat.com>
 
        PR c++/87768
index bc9d53800f7cd2e76c483262455ce3ed094177be..e654750d249d7139394be767278b0e9f5ac2bf49 100644 (file)
@@ -3438,10 +3438,9 @@ process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
     }
 
   /* In a lambda within a template, wait until instantiation
-     time to implicitly capture.  */
+     time to implicitly capture a dependent type.  */
   if (context == containing_function
-      && DECL_TEMPLATE_INFO (containing_function)
-      && uses_template_parms (DECL_TI_ARGS (containing_function)))
+      && dependent_type_p (TREE_TYPE (decl)))
     return decl;
 
   if (lambda_expr && VAR_P (decl)
index 5425e8261a1499bcd45c991db37f64c6575a6999..3075f478bdb010e09698eaf3080588564db70dcc 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-17  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/86610
+       * g++.dg/cpp0x/pr86610.C: New.
+
 2019-01-17  Wei Xiao  <wei3.xiao@intel.com>
 
        * gcc.target/i386/avx512f-vfixupimmpd-2.c: Fix the test cases for
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr86610.C b/gcc/testsuite/g++.dg/cpp0x/pr86610.C
new file mode 100644 (file)
index 0000000..dc0e2f5
--- /dev/null
@@ -0,0 +1,31 @@
+// { dg-do run { target c++11 } }
+// PR c++86610 lambda capture inside template
+
+struct C
+{
+  int operator[](int)
+  { return 1; }
+
+  int operator[](int) const
+  { return 0; } // Want this one
+};
+
+int q()
+{
+  C c;
+  return [=] { return c[0]; }();
+}
+
+template <typename T>
+int f()
+{
+  C c;
+  T d;
+  return [=] { return c[0]; }() 
+    + [=] { return c[0] + d[0]; }();
+}
+
+int main()
+{
+  return q () + f<C>();
+}
This page took 0.085462 seconds and 5 git commands to generate.