From f3ee91e70df8a7fdc68f46427bf8a28f34f0cd24 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 2 Oct 2021 13:57:01 +0300 Subject: [PATCH] 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. --- source/core/tag.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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); -- 2.43.0