Seems to be a mistake in lambda MS VC2010 expressions?

The behavior of the lambda expression used in static initializers magically depends on local variables initialized inside the lambda body

int static_1 = [=]() -> int { int k_=7;// if this statement presents, the lambda doesn't work (static_1 remains uninitialized) return 5; } (); int static_2= [=]() -> int { //Ok without variable initializer int k_=7; return 5; }(); int main() { int local= [=]() -> int { int k_=7; // Ok with variable initializer when lambda used in local function context return 5; } (); printf("\n static_1= %d \n static_2= %d \n local= %d", static_1,static_2,local); } 
+4
source share
1 answer

I don’t see anything in the final draft, which would lead to the expectation of such behavior (especially since it happens quietly).

I reproduced the problem in VS10, and the behavior in GCC 4.5.0 is as expected (all variables are initialized), so I would say yes, this is an error in VS10, did you find an error?


Update: I sent this error and received a response:

Thanks for submitting this issue. This was a bug in our lambda implementation and fixed. The fix should be available in the next version of Visual Studio (and possibly Visual Studio 2010 SP1, although I cannot guarantee this).

+2
source

Source: https://habr.com/ru/post/1316266/


All Articles