[cfe-users] problem: templated static variable and multiple compilation units
prg at Ichthyostega.de
Tue Oct 8 14:07:57 PDT 2013
-----BEGIN PGP SIGNED MESSAGE-----
not sure if this is a problem of Clang, or of GCC or the libstdc++ on Linux --
or if our expectation how C++ should behave are "broken". Maybe someone can shed
some light into this problem.
We tried compiling the GCC developed code base of our opensource project with
Clang. After fixing some minor problems to make the compilation succeed, we
noticed broken unit tests: Some application service, implemented as a
singleton, was instantiated multiple times in the Clang compiled executable.
I've tracked down the problem and extracted a demonstration. Initially I've
posted this as a question to stackoverflow; but maybe here is even a better
place to ask about such a somewhat slightly more involved situation.
Basically we have single instance of a class (a singleton factory) holding this
templated static variable (for the singleton instance). But when we use the
access function, which is inline, from multiple compilation units, different
memory locations are emitted for the same static variable. Accessing if from
within the same compilation unit works as expected.
We're observing this problem on Debian/stable 64bit (Clang-3.0 vs GCC-4.7);
we could reproduce same the behaviour on Debian/testing 32bit (Clang-3.2)
If necessary/helpful, I could repost the code here or provide additional
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Icedove - http://www.enigmail.net/
-----END PGP SIGNATURE-----
More information about the cfe-users