Foo* getInstance()
{
static Foo;
return foo;
}
This is perfectly valid.Unfortunately, getInstance() was implemented in Foo.h, not in Foo.cpp. But in C++, functions in header files are inline by default. This means that every caller of Foo::getInstance() wound up with their own "static Foo" in their own inlined Foo::getInstance(), which meant that each caller got a different instance of the Singleton.
Most interesting bug I've seen in ten years.