In the example below, gcc complains about this not being captures. This happens whenever a pointer to a member function is requested in a lambda. I tested with gcc-4.7.2. struct Test { void y() { } void x() { [](Test &t) { (t.*(&Test::y))(); }(*this); } }; int main() { Test().x(); }
I don't think this is legal, when y isn't static I mean (otherwise it would be a dup of PR55828). Daniel, what do you think?
The code looks valid to me, I don't see any reason for capturing something here. The expression "&Test::y" should be valid in that scope and returns an rvalue.
Ok, confirmed.
Related to 51494.
Author: jason Date: Fri Mar 8 16:03:48 2013 New Revision: 196549 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196549 Log: PR c++/51494 PR c++/51884 PR c++/56222 * tree.c (maybe_dummy_object): Don't capture 'this'. * semantics.c (maybe_resolve_dummy): New. (finish_non_static_data_member): Use it. (finish_qualified_id_expr): Don't test is_dummy_object. * cp-tree.h: Declare maybe_resolve_dummy. * call.c (build_new_method_call_1): Use it. Added: trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this11.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c trunk/gcc/cp/cp-tree.h trunk/gcc/cp/semantics.c trunk/gcc/cp/tree.c
Fixed for 4.8.
This issue applies to 4.7.x too. Any chance to get this backported?
Now that 4.8.0 is about to be released, I'm reluctant to backport non-regression C++11 fixes to 4.7.