Bug 46047

Summary: Lambda expressions: access to member functions
Product: gcc Reporter: Mikhail Semenov <mikhail_semenov>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 4.5.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Mikhail Semenov 2010-10-16 14:45:32 UTC
According to the latest C++0x draft (n3126), 'this' is not required in front of
the member variable 'f' (there are a few examples on this issue in the draft).
As far as I understand, the same should apply to a member function. In GCC 4.5.0, the use of inc(n) without   the prefix "this->" causes an error.

struct S10 
{
	int f;
	double p;
        void inc(int& a) { a += f;}
	void work(int n) 
	{
		int m = n*n;
		int j = 40;
		f = 10;
		p =3.7;
		auto m3 = [this,&n]() mutable -> int
		{
			p++;
			f++;       
                        inc(n); //this-> required in 4.5.0               
			return n;
		};
		cout << "S9 m3():" << m3() << endl;
		cout << "f:" << f << " p:" << p << " n:" << n << endl;
	}
};
Comment 1 Jonathan Wakely 2010-10-16 15:24:26 UTC
compiles without error in 4.5.2 and 4.6.0 (once the necessary <iostream> and using directive are added)
Comment 2 Jonathan Wakely 2010-10-16 15:26:29 UTC
*** Bug 46048 has been marked as a duplicate of this bug. ***