aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2019-01-17 11:56:58 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2019-01-17 11:56:58 +0000
commite32fc4499f863fe0fa81767d11f40ad2f1ab1668 (patch)
tree74d7a86f509de000262ea8da0863b3d4b9560707 /gcc
parentfc881de2825e37142436efcfd7537cc467f3430c (diff)
downloadgcc-e32fc4499f863fe0fa81767d11f40ad2f1ab1668.zip
gcc-e32fc4499f863fe0fa81767d11f40ad2f1ab1668.tar.gz
gcc-e32fc4499f863fe0fa81767d11f40ad2f1ab1668.tar.bz2
[PR c++/86610] lambda captures in templates
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/semantics.c5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/pr86610.C31
4 files changed, 44 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 524fbd3..dec8d64 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index bc9d538..e654750 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5425e82..3075f47 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..dc0e2f5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr86610.C
@@ -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>();
+}