Simple example:
class Foo {
int x;
void bar(int x) {
[this]() -> void {
x = 6;
}();
}
};
This doesn't compile on GCC, Clang, MVC, or ICC (see it live). If I change void bar(int x) to void bar(int y), or if I change x = 6; to this->x = 6; then it works fine.
This doesn't make sense to me. The local variable x from the call to bar is deliberately not being captured in the lambda. The only x that makes sense is Foo's member variable.
Question: Is this the expected behavior, and iff so, please explain why?