From cdb3d3045a7f7949ff22b09e1934911e2c83d260 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 6 Oct 2013 18:58:32 +0200 Subject: [PATCH] BUG: Clang shows a problem when accessing templated static variable through separate compilation units this is really creepy: the same(!) instance of the singleton factory sees different addresses of the class static variable, depending on the compilation unit. Please note that the type of the concrete factory function is *erased* when exiting the constructor function of ConfigurableHolder --- research/clang-static-init-1.cpp | 16 +++++++++++++--- research/clang-static-init.hpp | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/research/clang-static-init-1.cpp b/research/clang-static-init-1.cpp index 020f469b3..6c473de41 100644 --- a/research/clang-static-init-1.cpp +++ b/research/clang-static-init-1.cpp @@ -2,16 +2,26 @@ #include "clang-static-init.hpp" +test::Subject& +localFunction() +{ + return test::fab.get(); +} + int main (int, char**) { - cout << "\nStart Testcase: invoking two instances of the configurable singleton factory...\n"; + cout << "\nStart Testcase: invoking two instances of the configurable singleton factory...\n\n"; test::Subject& ref1 = test::fab.get(); - test::Subject& sub2 = test::fabricate(); + test::Subject& sub2 = test::fabricate(); ///NOTE: invoking get() from within another compilation unit reveales the problem + test::Subject& sub3 = localFunction(); - cout << "sub1="<< &ref1 << " sub2="<< &sub2 <<"\n"; + cout << "sub1=" << &ref1 + << "\nsub2="<< &sub2 + << "\nsub3="<< &sub3 + << "\n"; return 0; diff --git a/research/clang-static-init.hpp b/research/clang-static-init.hpp index 6597e8b05..272e76d08 100644 --- a/research/clang-static-init.hpp +++ b/research/clang-static-init.hpp @@ -22,7 +22,7 @@ namespace test { { if (!instance) { - cout << "Singleton Factory: invoke Fabrication ---> instance="<<&instance<<"...\n"; + cout << "Singleton Factory: invoke Fabrication ---> address of static instance variable: "<<&instance<<"...\n"; instance = Fac::create(); }