This seems to be a bug, and lambda in the catch scope is generated outside the class. I tried to prove that with types, but the Visual Studio lambda names are strangely crippled, and the name itself proves nothing. However, the error codes generated by the following snippet show that the names are different:
#include <iostream> #include <typeinfo> class Foo { private: public: void testLambda() try { auto tryScope = [this]() {}; void (*p)() = tryScope; } catch(...) { auto catchScope = [this]() {}; void (*p)() = catchScope; } };
Error output:
(10): error C2440: 'initializing' : cannot convert from 'Foo::testLambda::<lambda_8a3a8afea7359de4568df0e75ead2a56>' to 'void (__cdecl *)(void)' (15): error C2440: 'initializing' : cannot convert from '<lambda_8cbc08e7748553fb5ae4e39184491e92>' to 'void (__cdecl *)(void)'
source share