From a546927c6a9a06b25ae85f8206b2c7afc53f4a45 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 22 Sep 2014 15:22:11 -0400 Subject: [PATCH] =?utf8?q?re=20PR=20c++/63320=20(bogus=20=E2=80=98this?= =?utf8?q?=E2=80=99=20was=20not=20captured=20for=20this=20lambda=20functio?= =?utf8?q?n=20error)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit PR c++/63320 PR c++/60463 PR c++/60755 * lambda.c (maybe_resolve_dummy, lambda_expr_this_capture): Handle not finding 'this'. From-SVN: r215478 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/lambda.c | 8 +++++--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C | 4 ++-- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this19.C | 11 +++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this19.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7d23a773ab1..f209e15794e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2014-09-22 Jason Merrill + + PR c++/63320 + PR c++/60463 + PR c++/60755 + * lambda.c (maybe_resolve_dummy, lambda_expr_this_capture): Handle + not finding 'this'. + 2014-09-22 Paolo Carlini PR c++/62219 diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 0d8d4551a0f..17fd0377eb9 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -724,7 +724,8 @@ lambda_expr_this_capture (tree lambda, bool add_capture_p) if (!this_capture) { - error ("% was not captured for this lambda function"); + if (add_capture_p) + error ("% was not captured for this lambda function"); result = error_mark_node; } else @@ -768,8 +769,9 @@ maybe_resolve_dummy (tree object, bool add_capture_p) /* In a lambda, need to go through 'this' capture. */ tree lam = CLASSTYPE_LAMBDA_EXPR (current_class_type); tree cap = lambda_expr_this_capture (lam, add_capture_p); - object = build_x_indirect_ref (EXPR_LOCATION (object), cap, - RO_NULL, tf_warning_or_error); + if (cap != error_mark_node) + object = build_x_indirect_ref (EXPR_LOCATION (object), cap, + RO_NULL, tf_warning_or_error); } return object; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C index 03a7a4bb60d..9c76d34496d 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C @@ -3,7 +3,7 @@ class Klass { - unsigned int local; + unsigned int local; // { dg-error "non-static" } public: bool dostuff(); }; @@ -11,7 +11,7 @@ public: bool Klass::dostuff() { auto f = []() -> bool { - if (local & 1) { return true; } // { dg-error "not captured" } + if (local & 1) { return true; } // { dg-error "not captured|this location" } return false; }; } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this19.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this19.C new file mode 100644 index 00000000000..c4c041f8b30 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this19.C @@ -0,0 +1,11 @@ +// PR c++/63320 +// { dg-do compile { target c++11 } } + +class A { + static void addWindow(); + static void activateWindow(void *); +}; +void A::addWindow() { + int* action {}; + [action] { activateWindow(action); }; +} -- 2.30.2