G++ 4.6.3 Lambda BUG ?
gbb21 2012-08-02 09:43:05 Following Code will fail to compile
1 #include <iostream>
2 #include <vector>
3
4 using namespace std;
5
6 template <typename T>
7 struct MyClass
8 {
9 int func()
10 {
11 return 0;
12 }
13
14 void test()
15 {
16 [=] {
17 func(); // It will be fine if I change it into this->func();
18 }();
19 }
20 };
21
22 int main()
23 {
24 MyClass<int> c;
25 c.test();
26 return 3;
27 }
18:35:Dashboard$g++ -std=c++0x a.cpp
a.cpp: In lambda function:
a.cpp:16:5: instantiated from ‘MyClass<T>::test() [with T = int]::<lambda()>’
a.cpp:16:3: instantiated from ‘void MyClass<T>::test() [with T = int]’
a.cpp:25:9: instantiated from here
a.cpp:17:4: error: ‘func’ was not declared in this scope
Is this a bug or standard behavior ? Thx.