From 675b2070ce4f82433e02906fa30964717f939bc1 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 6 Oct 2013 17:37:01 +0200 Subject: [PATCH] bughunt: attempt to rebuild the problematic structure stand-alone... --> MISS this is only a stripped-down version of the basic singleton, without the indirection. Unsurprisingly, this doesn't exhibit the problem yet --- research/SConscript | 2 +- research/clang-static-init-1.cpp | 4 +--- research/clang-static-init-2.cpp | 6 +++--- research/clang-static-init.hpp | 32 +++++++++++++++++++++++--------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/research/SConscript b/research/SConscript index 282a4b1e4..11f58d5c9 100644 --- a/research/SConscript +++ b/research/SConscript @@ -14,7 +14,7 @@ envR.Append(CPPPATH='research') # build additional test and administrative tools.... experiments = [ envR.Program('try', ['try.cpp'] + support_lib) #### to try out some feature... - , envR.Program('clang-static-init', ['clang-static-init-1.cpp', 'clang-static-init-2.cpp'] + core) + , envR.Program('clang-static-init', ['clang-static-init-1.cpp', 'clang-static-init-2.cpp']) ] # diff --git a/research/clang-static-init-1.cpp b/research/clang-static-init-1.cpp index 027c4ef1f..7170aa999 100644 --- a/research/clang-static-init-1.cpp +++ b/research/clang-static-init-1.cpp @@ -1,11 +1,9 @@ -#include "lib/test/run.hpp" #include "clang-static-init.hpp" #include -using ::test::Test; using std::cout; using std::endl; @@ -16,7 +14,7 @@ main (int, char**) { cout << "\n.gulp.\n"; - Subject& ref1 = fab(); + Subject& ref1 = fab.get(); 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 8b4c375ba..80cba771e 100644 --- a/research/clang-static-init-2.cpp +++ b/research/clang-static-init-2.cpp @@ -20,16 +20,16 @@ namespace test { namespace { - lib::singleton::UseSubclass typeID; + // } - Factory fab(typeID); + AccessPoint fab; Subject& fabricate() { - return fab(); + return fab.get(); } diff --git a/research/clang-static-init.hpp b/research/clang-static-init.hpp index cd4682381..f0694fd6b 100644 --- a/research/clang-static-init.hpp +++ b/research/clang-static-init.hpp @@ -1,12 +1,10 @@ -#include "lib/error.hpp" - -#include "lib/singleton-subclass.hpp" - namespace test { - template + template class Fac + > struct Holder { static T* instance; @@ -16,15 +14,31 @@ namespace test { { if (!instance) { - instance = new T(); + instance = Fac::create(); } return *instance; } }; + template class F + > + T* Holder::instance; + + + template - T* Holder::instance; + struct Factory + { + static T* + create() + { + return new T(); + } + }; + + struct Subject { @@ -34,9 +48,9 @@ namespace test { }; - typedef lib::SingletonSub Factory; + typedef Holder AccessPoint; - extern Factory fab; + extern AccessPoint fab;