I was trying out an example presented at CppCon that uses lambdas. And to my surprise the program don't compile in gcc and clang(in either C++14 or C++17) but compiles in msvc. This can be verified here.
For reference, the example code is as follows:
#include <stdio.h>
int g = 10;
auto kitten = [=]() { return g+1; };
auto cat = [g=g]() { return g+1; };
int main() {
g = 20;
printf("%d %d\n", kitten(), cat());
}
What is the problem here(if any) and which compiler is right?
Note that the code is an exact copy-paste from their official presentation slide.