As proposed in the paper P0409R2
I am expecting the definition of x to be deprecated from C++20 and fail to compile but it seems to work in g++ (GCC) 8.1.0 does anyone know if I am doing anything wrong?
In Visual Studio 2017 is fails to compiler with an error around the definition of y. error C3791: 'this' cannot be explicitly captured when the default capture mode is by copy (=)
#include <iostream>
struct X {
void f()
{
int value = 3;
auto x = [=] { // Deprecated from C++20:
return value + g();
};
auto y = [=, this] { // Recommended method from C++20:
return value + g(); // [=] The this pointer will not be captured, so capture with specifying this
};
}
int g() const
{
return 2;
}
};
int main()
{
X().f();
}