From: Mikko Rasa Date: Sat, 2 Oct 2021 10:57:01 +0000 (+0300) Subject: Access the tag name map with a function X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f3ee91e70df8a7fdc68f46427bf8a28f34f0cd24;p=libs%2Fgl.git Access the tag name map with a function Otherwise declaring tag constants as static members of classes is unreliable because of the undefined initialization order of globals in different translation units. --- diff --git a/source/core/tag.cpp b/source/core/tag.cpp index 44c7c8f8..56236c19 100644 --- a/source/core/tag.cpp +++ b/source/core/tag.cpp @@ -9,7 +9,11 @@ using namespace std; namespace { #ifdef DEBUG -map tag_names; +map &get_tag_names() +{ + static map names; + return names; +} #endif } @@ -22,7 +26,7 @@ Tag::Tag(const char *s): { #ifdef DEBUG if(s) - tag_names.insert(make_pair(*this, string(s))); + get_tag_names().insert(make_pair(*this, string(s))); #endif } @@ -31,15 +35,16 @@ Tag::Tag(const string &s): { #ifdef DEBUG if(!s.empty()) - tag_names.insert(make_pair(*this, s)); + get_tag_names().insert(make_pair(*this, s)); #endif } string Tag::str() const { #ifdef DEBUG - auto i=tag_names.find(*this); - if(i!=tag_names.end()) + const auto &names = get_tag_names(); + auto i = names.find(*this); + if(i!=names.end()) return i->second; #endif return format("Tag(%d)", id);