Bug 56222 - Pointer to member in lambda should not require this to be captured
Summary: Pointer to member in lambda should not require this to be captured
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 4.8.0
Assignee: Jason Merrill
URL:
Keywords: c++-lambda
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2013-02-06 11:08 UTC by Boris Bigott
Modified: 2022-03-11 00:32 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-02-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Bigott 2013-02-06 11:08:58 UTC
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(); }
Comment 1 Paolo Carlini 2013-02-06 11:32:40 UTC
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?
Comment 2 Daniel Krügler 2013-02-06 11:42:21 UTC
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.
Comment 3 Paolo Carlini 2013-02-06 11:55:51 UTC
Ok, confirmed.
Comment 4 Jason Merrill 2013-03-05 17:46:53 UTC
Related to 51494.
Comment 5 Jason Merrill 2013-03-08 16:03:57 UTC
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
Comment 6 Jason Merrill 2013-03-08 16:09:29 UTC
Fixed for 4.8.
Comment 7 Michael Bruck 2013-03-17 21:12:24 UTC
This issue applies to 4.7.x too. Any chance to get this backported?
Comment 8 Jason Merrill 2013-03-18 03:51:11 UTC
Now that 4.8.0 is about to be released, I'm reluctant to backport non-regression C++11 fixes to 4.7.