diff --git a/src/blackgui/guiutility.cpp b/src/blackgui/guiutility.cpp index c854928a9..d90475a0a 100644 --- a/src/blackgui/guiutility.cpp +++ b/src/blackgui/guiutility.cpp @@ -116,6 +116,8 @@ namespace BlackGui return (mw && mw->isFrameless()); } + static QThreadStorage tsRegex; + bool CGuiUtility::lenientTitleComparison(const QString &title, const QString &comparison) { if (title == comparison) { return true; } @@ -127,7 +129,6 @@ namespace BlackGui if (t == c) { return true; } // further unify - static QThreadStorage tsRegex; if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("[^a-z0-9\\s]")); } const QRegularExpression ®exp = tsRegex.localData(); t = t.remove(regexp); diff --git a/src/blackmisc/algorithm.h b/src/blackmisc/algorithm.h index 1771f6c47..57ac10c1f 100644 --- a/src/blackmisc/algorithm.h +++ b/src/blackmisc/algorithm.h @@ -50,6 +50,9 @@ namespace BlackMisc //! \threadsafe inline std::mt19937 &defaultRandomGenerator() { + //! \fixme Move rng to namespace scope to ensure destruction after function-local statics + //! and avoid warning "thread exited after QThreadStorage destroyed". + //! This will require careful thought about linkage. static QThreadStorage rng; if (rng.hasLocalData()) { rng.setLocalData(std::mt19937(static_cast(QRandomGenerator::global()->generate()))); } return rng.localData(); diff --git a/src/blackmisc/jsonexception.cpp b/src/blackmisc/jsonexception.cpp index 76b32246a..e363d268b 100644 --- a/src/blackmisc/jsonexception.cpp +++ b/src/blackmisc/jsonexception.cpp @@ -17,11 +17,12 @@ namespace BlackMisc { + static QThreadStorage> g_stack; + //! \private auto &jsonStack() noexcept { - static QThreadStorage> stack; - return stack.localData(); + return g_stack.localData(); } // pin vtables to this file diff --git a/src/blackmisc/logcategorylist.h b/src/blackmisc/logcategorylist.h index 0692481b8..420c43d07 100644 --- a/src/blackmisc/logcategorylist.h +++ b/src/blackmisc/logcategorylist.h @@ -114,7 +114,7 @@ namespace BlackMisc static const CLogCategoryList &fromClass() { static_assert(sizeof(T) > 0, "T must be a complete type, not forward declared"); - static QThreadStorage list; + static QThreadStorage list; //! \todo C++17: make list an inline static member variable template if (! list.hasLocalData()) { list.localData().appendCategoriesFromMemberFunction(tag(), THasGetLogCategories());