From e32fc4499f863fe0fa81767d11f40ad2f1ab1668 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 17 Jan 2019 11:56:58 +0000 Subject: [PATCH] [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 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/semantics.c | 5 ++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/pr86610.C | 31 ++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr86610.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 524fbd366c0..dec8d64d46f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-01-17 Nathan Sidwell + + PR c++/86610 + * semantics.c (process_outer_var_ref): Only skip dependent types + in templates. + 2019-01-17 Alexandre Oliva PR c++/87768 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index bc9d53800f7..e654750d249 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 5425e8261a1..3075f478bdb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-17 Nathan Sidwell + + PR c++/86610 + * g++.dg/cpp0x/pr86610.C: New. + 2019-01-17 Wei Xiao * 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 00000000000..dc0e2f5d52e --- /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 +int f() +{ + C c; + T d; + return [=] { return c[0]; }() + + [=] { return c[0] + d[0]; }(); +} + +int main() +{ + return q () + f(); +} -- 2.30.2