From 525dcd0c421c26633a100374245de7be98ffa7bb Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 25 Mar 2013 20:35:43 +0000 Subject: [PATCH] PR c++/52014 * semantics.c (lambda_expr_this_capture): Don't capture 'this' in unevaluated context. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@197063 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 +++ gcc/cp/semantics.c | 10 ++--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this14.C | 49 +++++++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1209a8b6261..bac48449830 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-03-23 Jason Merrill + + PR c++/52014 + * semantics.c (lambda_expr_this_capture): Don't capture 'this' in + unevaluated context. + 2013-03-25 Paolo Carlini PR c++/56722 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e3aeb817a52..fb38e8d7011 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9454,6 +9454,11 @@ lambda_expr_this_capture (tree lambda) tree this_capture = LAMBDA_EXPR_THIS_CAPTURE (lambda); + /* In unevaluated context this isn't an odr-use, so just return the + nearest 'this'. */ + if (cp_unevaluated_operand) + return lookup_name (this_identifier); + /* Try to default capture 'this' if we can. */ if (!this_capture && LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda) != CPLD_NONE) @@ -9523,11 +9528,6 @@ lambda_expr_this_capture (tree lambda) if (!this_capture) { - /* In unevaluated context this isn't an odr-use, so just return the - nearest 'this'. */ - if (cp_unevaluated_operand) - return lookup_name (this_identifier); - error ("% was not captured for this lambda function"); result = error_mark_node; } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this14.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this14.C new file mode 100644 index 00000000000..9834bfdb308 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this14.C @@ -0,0 +1,49 @@ +// PR c++/52014 +// { dg-require-effective-target c++11 } + +template +void for_each(const Iterator first, const Iterator last, Func func) +{ + for (Iterator it = first; it != last; ++it) { + func(*it); + } +} + +template +struct helper +{ + typedef typename T::size_type type; +}; + +template +struct helper +{ + typedef typename T::size_type type; +}; + +template +struct helper +{ + typedef typename T::size_type type; +}; + +struct bar +{ + struct foo + { + typedef int size_type; + } foo_; + + void test() + { + int arr[] = { 1, 2, 3 }; + for_each(arr, arr + 3, [&](helper::type i) { + for_each(arr, arr + 3, [&](helper::type j) { }); + }); + } +}; + +int main() +{ + return 0; +} -- 2.11.4.GIT