From 1b1a176f7707566e5684cfc17c9763ce7f33706a Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 8 Mar 2013 16:04:02 +0000 Subject: [PATCH] * semantics.c (lambda_expr_this_capture): In unevaluated context, just return the nearest 'this'. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196550 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/semantics.c | 5 +++++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this12.C | 13 +++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this12.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f9731a5538e..0aa5b4bb071 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2013-03-08 Jason Merrill + * semantics.c (lambda_expr_this_capture): In unevaluated context, + just return the nearest 'this'. + PR c++/51494 PR c++/51884 PR c++/56222 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index d11a4e4b218..233765a936f 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9513,6 +9513,11 @@ 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-this12.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this12.C new file mode 100644 index 00000000000..ef573b19e02 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this12.C @@ -0,0 +1,13 @@ +// Uses of 'this' in unevaluated context are not odr-uses. +// { dg-do compile { target c++11 } } + +struct A +{ + int f() {} + int i; + + void foo() + { + [] () { sizeof(i); sizeof(f()); }; + } +}; -- 2.11.4.GIT