From 7492e7ffceeb60b389a80b5166fe2ccebf4f87be Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 25 Sep 2014 02:50:02 +0200 Subject: [PATCH] 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. --- tests/core/proc/mobject/session/defs-registry-impl-test.cpp | 4 +--- tests/library/meta/generator-test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/core/proc/mobject/session/defs-registry-impl-test.cpp b/tests/core/proc/mobject/session/defs-registry-impl-test.cpp index 3ab595ac5..dddebd38e 100644 --- a/tests/core/proc/mobject/session/defs-registry-impl-test.cpp +++ b/tests/core/proc/mobject/session/defs-registry-impl-test.cpp @@ -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 - string Dummy::name = (typePatt % I); + string Dummy::name = _Fmt("Dummy<%2i>") % I; template inline P > diff --git a/tests/library/meta/generator-test.cpp b/tests/library/meta/generator-test.cpp index 2e5978660..b1df2a5e7 100644 --- a/tests/library/meta/generator-test.cpp +++ b/tests/library/meta/generator-test.cpp @@ -44,6 +44,7 @@ #include #include +using util::_Fmt; using std::string; using std::cout; @@ -61,10 +62,9 @@ namespace test { }; - util::_Fmt fmt ("Block<%2i>"); template - string Block::name = string (fmt % I); + string Block::name = _Fmt("Block<%2i>") % I;