Bug 46047 - Lambda expressions: access to member functions
Summary: Lambda expressions: access to member functions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 46048 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-10-16 14:45 UTC by Mikhail Semenov
Modified: 2010-10-16 15:26 UTC (History)
0 users

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 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. ***