Bug 48523

Summary: [C++0x] lambda cannot capture 'this' in class template
Product: gcc Reporter: Jonathan Wakely <redi>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: jason
Priority: P3 Keywords: rejects-valid
Version: 4.6.0   
Target Milestone: 4.6.1   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

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.