Bug 48523 - [C++0x] lambda cannot capture 'this' in class template
Summary: [C++0x] lambda cannot capture 'this' in class template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-04-08 22:26 UTC by Jonathan Wakely
Modified: 2011-04-12 00:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2011-04-08 22:26:14 UTC
template<typename>
struct X
{
  bool b;

  void f()
  {
    [this]{ return b; };
  }
};

X<int> x;

l.cc: In lambda function:
l.cc:8:20: error: invalid type argument (have ‘decltype (this)’)

The same lambda works fine in a non-template class
Comment 1 Jason Merrill 2011-04-11 22:00:27 UTC
Author: jason
Date: Mon Apr 11 22:00:20 2011
New Revision: 172283

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172283
Log:
	PR c++/48523
	* tree.c (maybe_dummy_object): Use build_x_indirect_ref rather
	than cp_build_indirect_ref.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/tree.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Jason Merrill 2011-04-12 00:20:23 UTC
Author: jason
Date: Tue Apr 12 00:20:18 2011
New Revision: 172293

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172293
Log:
	PR c++/48523
	* tree.c (maybe_dummy_object): Use build_x_indirect_ref rather
	than cp_build_indirect_ref.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this4.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/tree.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2011-04-12 00:32:18 UTC
Fixed for 4.6.1.