From 80b6bcc385863a38d499685af9b8e857e46cbdba Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 31 Jan 2022 17:19:06 +0100 Subject: Short live Q_CONSTINIT! It expands to the first available of - constinit (C++20) - [[clang::require_constant_initialization]] (Clang) - __constinit (GCC >= 10) Use it around the code (on and near static QBasicAtomic; this patch makes no attempt to find all statics in qtbase). [ChangeLog][QtCore][QtGlobal] Added macro Q_CONSTINIT. Fixes: QTBUG-100484 Change-Id: I11e0363a7acb3464476859d12ec7f94319d82be7 Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot --- src/dbus/qdbus_symbols.cpp | 4 ++-- src/dbus/qdbusintegrator.cpp | 12 ++++++------ src/dbus/qdbusmetaobject.cpp | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/dbus') diff --git a/src/dbus/qdbus_symbols.cpp b/src/dbus/qdbus_symbols.cpp index bd4299809b..0eccbe669e 100644 --- a/src/dbus/qdbus_symbols.cpp +++ b/src/dbus/qdbus_symbols.cpp @@ -79,8 +79,8 @@ bool qdbus_loadLibDBus() return false; #endif - static bool triedToLoadLibrary = false; - static QBasicMutex mutex; + Q_CONSTINIT static bool triedToLoadLibrary = false; + Q_CONSTINIT static QBasicMutex mutex; const auto locker = qt_scoped_lock(mutex); QLibrary *&lib = qdbus_libdbus; diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 7efd94ac77..9ddaf8d4c1 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -1991,14 +1991,14 @@ public: #if defined(QT_NO_DEBUG) // when in a release build, we default these to off. // this means that we only affect code that explicitly enables the warning. - static int mainThreadWarningAmount = -1; - static int otherThreadWarningAmount = -1; + Q_CONSTINIT static int mainThreadWarningAmount = -1; + Q_CONSTINIT static int otherThreadWarningAmount = -1; #else - static int mainThreadWarningAmount = 200; - static int otherThreadWarningAmount = 500; + Q_CONSTINIT static int mainThreadWarningAmount = 200; + Q_CONSTINIT static int otherThreadWarningAmount = 500; #endif - static bool initializedAmounts = false; - static QBasicMutex initializeMutex; + Q_CONSTINIT static bool initializedAmounts = false; + Q_CONSTINIT static QBasicMutex initializeMutex; auto locker = qt_unique_lock(initializeMutex); if (!initializedAmounts) { diff --git a/src/dbus/qdbusmetaobject.cpp b/src/dbus/qdbusmetaobject.cpp index bf42736eab..090862a222 100644 --- a/src/dbus/qdbusmetaobject.cpp +++ b/src/dbus/qdbusmetaobject.cpp @@ -144,8 +144,8 @@ static int registerComplexDBusType(const QByteArray &typeName) {} }; - static QBasicMutex mutex; - static struct Hash : QHash + Q_CONSTINIT static QBasicMutex mutex; + Q_CONSTINIT static struct Hash : QHash { ~Hash() { -- cgit v1.2.3