From 0e8a1f1e08e4c24d77d4ffa03df7cc19cff75cc5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 30 Sep 2013 02:09:31 +0200 Subject: [PATCH] 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 --- research/clang-static-init-1.cpp | 4 +--- research/clang-static-init-2.cpp | 7 ++++--- research/clang-static-init.hpp | 5 ++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/research/clang-static-init-1.cpp b/research/clang-static-init-1.cpp index 366b53a83..027c4ef1f 100644 --- a/research/clang-static-init-1.cpp +++ b/research/clang-static-init-1.cpp @@ -16,9 +16,7 @@ main (int, char**) { cout << "\n.gulp.\n"; - Factory fab1; - Subject& ref1 = fab1(); - + Subject& ref1 = fab(); Subject& sub2 = test::fabricate(); cout << "sub1="<< &ref1 << " sub2="<< &sub2 <<"\n"; diff --git a/research/clang-static-init-2.cpp b/research/clang-static-init-2.cpp index b9a95f1b2..8b4c375ba 100644 --- a/research/clang-static-init-2.cpp +++ b/research/clang-static-init-2.cpp @@ -20,15 +20,16 @@ namespace test { namespace { -// Holder fab2; - Factory fab2; + lib::singleton::UseSubclass typeID; } + Factory fab(typeID); + Subject& fabricate() { - return fab2(); + return fab(); } diff --git a/research/clang-static-init.hpp b/research/clang-static-init.hpp index 6a0b13da9..cd4682381 100644 --- a/research/clang-static-init.hpp +++ b/research/clang-static-init.hpp @@ -34,7 +34,10 @@ namespace test { }; - typedef lib::Singleton Factory; + typedef lib::SingletonSub Factory; + + extern Factory fab; + Subject& fabricate();