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
This commit is contained in:
Fischlurch 2013-10-06 18:58:32 +02:00
parent 4bd9eeb8ee
commit cdb3d3045a
2 changed files with 14 additions and 4 deletions

View file

@ -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;

View file

@ -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<I>::create();
}