The situation should theoretically arise in the field of namespace, as @ Space_C0wb0y shows in the link to the comment .
#include <iostream>
int x = 12;
auto l = [&x](){ return x; };
int main() {
std::cout << l() << std::endl;
}
If it seems strange to you that GCC accepts this snippet, as the MSVC correctly rejects it with the following error message:
error C3480: 'x': lambda capture variable must be from the scope of the closing function
source
share