From 66a06427f9ad21da7e768175e8e683cc08a317c7 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Thu, 3 Jan 2019 02:01:09 +0000 Subject: [PATCH] Ref T495 Using QThreadStorage because thread_local caused a static destruction order fiasco. --- src/blackmisc/statusmessage.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/blackmisc/statusmessage.cpp b/src/blackmisc/statusmessage.cpp index d6c039dbc..9fc405bb0 100644 --- a/src/blackmisc/statusmessage.cpp +++ b/src/blackmisc/statusmessage.cpp @@ -18,11 +18,14 @@ #include #include +#include namespace BlackMisc { namespace Private { + QThreadStorage t_tempBuffer; // thread_local would be destroyed before function-scope statics, see T495 + QString arg(QStringView format, const QStringList &args) { if (format.isEmpty()) @@ -30,7 +33,7 @@ namespace BlackMisc return args.join(u' '); } - thread_local QString temp; + QString &temp = t_tempBuffer.localData(); temp.resize(0); // unlike clear(), resize(0) doesn't release the capacity if there are no implicitly shared copies for (auto it = format.begin(); ; )