lumiera_documentation/research/clang-static-init.hpp
Ichthyostega 0e8a1f1e08 bughunt: use a single SingletonSub instance in two compilation units --> HIT
basically this reproduces the problem in a simplified setup.
Especially note that we're going through a single instance of the factory,
yet still this single instance 'sees' two different locations of the
class static variable
2013-10-06 23:17:18 +02:00

48 lines
606 B
C++

#include "lib/error.hpp"
#include "lib/singleton-subclass.hpp"
namespace test {
template<typename T>
struct Holder
{
static T* instance;
T&
get()
{
if (!instance)
{
instance = new T();
}
return *instance;
}
};
template<typename T>
T* Holder<T>::instance;
struct Subject
{
static int cnt;
Subject();
};
typedef lib::SingletonSub<Subject> Factory;
extern Factory fab;
Subject& fabricate();
} // namespace test