Fix initialisation order problem, triggered in Clang (#928)
In Clang, static object fields are initialised from top to bottom, but before any other variables in anoymous namespaces. To the contrary, GCC evaluates *any* initialisation expression in the translation unit together from top to bottom. Thus, in the clang generated code, in two cases the static initialisation could use a not yet constructed local lib::_Fmt formatter object.
This commit is contained in:
parent
30686fdf82
commit
7492e7ffce
2 changed files with 3 additions and 5 deletions
|
|
@ -51,11 +51,9 @@ namespace test {
|
|||
|
||||
namespace { // Test helpers...
|
||||
|
||||
_Fmt typePatt ("Dummy<%2i>");
|
||||
_Fmt instancePatt ("obj_%s_%i");
|
||||
|
||||
|
||||
|
||||
/** create a random new ID */
|
||||
string
|
||||
newID (string prefix)
|
||||
|
|
@ -78,7 +76,7 @@ namespace test {
|
|||
};
|
||||
|
||||
template<int I>
|
||||
string Dummy<I>::name = (typePatt % I);
|
||||
string Dummy<I>::name = _Fmt("Dummy<%2i>") % I;
|
||||
|
||||
template<int I>
|
||||
inline P<Dummy<I> >
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using util::_Fmt;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
||||
|
|
@ -61,10 +62,9 @@ namespace test {
|
|||
};
|
||||
|
||||
|
||||
util::_Fmt fmt ("Block<%2i>");
|
||||
|
||||
template<int I>
|
||||
string Block<I>::name = string (fmt % I);
|
||||
string Block<I>::name = _Fmt("Block<%2i>") % I;
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue