This is the simplest example I could come up with that reproduces the problem.
template<class T>
struct X
{
static void foo()
{
static int z = 0;
[]{ z = 1; }();
}
};
int main()
{
X<int>::foo();
return 0;
}
I've tried it with MinGW 4.6 and 4.7, also g++ 4.6 in Ubuntu and all of them give me the link error "undefined reference to `z'". So now that makes me wonder if this is even legal. VC10 has no problem with it.
It works if X is normal class instead of a template. Also, I don't think it's related to lambdas cause I get the error even if I replace the lambda with a local class.