From 80b6bcc385863a38d499685af9b8e857e46cbdba Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 31 Jan 2022 17:19:06 +0100 Subject: [PATCH] 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/corelib/animation/qpropertyanimation.cpp | 2 +- src/corelib/animation/qvariantanimation.cpp | 2 +- src/corelib/global/qglobal.cpp | 29 ++++++- src/corelib/global/qglobal.h | 10 +++ src/corelib/global/qglobalstatic.h | 4 +- src/corelib/global/qlogging.cpp | 6 +- src/corelib/io/qfileselector.cpp | 2 +- src/corelib/io/qprocess_unix.cpp | 2 +- src/corelib/io/qsettings.cpp | 2 +- src/corelib/kernel/qcoreapplication.cpp | 4 +- src/corelib/kernel/qeventdispatcher_glib.cpp | 2 +- src/corelib/kernel/qobject.cpp | 2 +- src/corelib/plugin/qlibrary.cpp | 6 +- src/corelib/text/qlocale.cpp | 2 +- src/corelib/thread/qthreadpool.cpp | 4 +- src/corelib/thread/qthreadstorage.cpp | 2 +- src/corelib/time/qtimezoneprivate_tz.cpp | 2 +- src/dbus/qdbus_symbols.cpp | 4 +- src/dbus/qdbusintegrator.cpp | 12 +-- src/dbus/qdbusmetaobject.cpp | 4 +- src/gui/image/qimagereader.cpp | 2 +- src/gui/kernel/qguiapplication.cpp | 78 +++++++++---------- src/gui/kernel/qinputdevice.cpp | 2 +- src/gui/painting/qcolorspace.cpp | 2 +- src/network/access/qnetworkaccessmanager.cpp | 2 +- src/network/kernel/qauthenticator.cpp | 2 +- src/network/kernel/qnetworkinformation.cpp | 2 +- src/network/ssl/qtlsbackend.cpp | 2 +- src/plugins/platforms/xcb/qxcbeventqueue.cpp | 4 +- .../openssl/qsslsocket_openssl_symbols.cpp | 6 +- 30 files changed, 121 insertions(+), 84 deletions(-) diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index e375305f9f8..87151161acd 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -289,7 +289,7 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State newState, QPropertyAnimation *animToStop = nullptr; { - static QBasicMutex mutex; + Q_CONSTINIT static QBasicMutex mutex; auto locker = qt_unique_lock(mutex); typedef QPair QPropertyAnimationPair; typedef QHash QPropertyAnimationHash; diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index 026db981ea8..ca13506aa54 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -404,7 +404,7 @@ QBindable QVariantAnimation::bindableEasingCurve() typedef QList QInterpolatorVector; Q_GLOBAL_STATIC(QInterpolatorVector, registeredInterpolators) -static QBasicMutex registeredInterpolatorsMutex; +Q_CONSTINIT static QBasicMutex registeredInterpolatorsMutex; /*! \fn template void qRegisterAnimationInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 067172efa49..1bbabed781d 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -3344,7 +3344,7 @@ Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n) // In the C runtime on all platforms access to the environment is not thread-safe. We // add thread-safety for the Qt wrappers. -static QBasicMutex environmentMutex; +Q_CONSTINIT static QBasicMutex environmentMutex; /* Wraps tzset(), which accesses the environment, so should only be called while @@ -4114,6 +4114,33 @@ bool qunsetenv(const char *varName) \sa Q_LIKELY() */ +/*! + \macro Q_CONSTINIT + \relates + \since 6.4 + + \brief Enforces constant initialization when supported by the compiler. + + If the compiler supports the C++20 \c{constinit} keyword, Clang's + \c{[[clang::require_constant_initialization]]} or GCC's \c{__constinit}, + then this macro expands to the first one of these that is available, + otherwise it expands to nothing. + + Variables marked as \c{constinit} cause a compile-error if their + initialization would have to be performed at runtime. + + For constants, you can use \c{constexpr} since C++11, but \c{constexpr} + makes variables \c{const}, too, whereas \c{constinit} ensures constant + initialization, but doesn't make the variable \c{const}: + + \table + \header \li Keyword \li Added \li immutable \li constant-initialized + \row \li \c{const} \li C++98 \li yes \li not required + \row \li \c{constexpr} \li C++11 \li yes \li required + \row \li \c{constinit} \li C++20 \li no \li required + \endtable +*/ + /*! \macro QT_POINTER_SIZE \relates diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index e69e55977b9..18851cd1204 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1165,6 +1165,16 @@ constexpr std::underlying_type_t qToUnderlying(Enum e) noexcept #define Q_IMPLICIT #endif +#ifdef __cpp_constinit +# define Q_CONSTINIT constinit +#elif defined(__has_cpp_attribute) && __has_cpp_attribute(clang::require_constant_initialization) +# define Q_CONSTINIT [[clang::require_constant_initialization]] +#elif defined(Q_CC_GNU) && Q_CC_GNU >= 1000 +# define Q_CONSTINIT __constinit +#else +# define Q_CONSTINIT +#endif + template inline T *qGetPtrHelper(T *ptr) noexcept { return ptr; } template inline auto qGetPtrHelper(Ptr &ptr) noexcept -> decltype(ptr.get()) { static_assert(noexcept(ptr.get()), "Smart d pointers for Q_DECLARE_PRIVATE must have noexcept get()"); return ptr.get(); } diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h index aaa01262a70..beecc1f000a 100644 --- a/src/corelib/global/qglobalstatic.h +++ b/src/corelib/global/qglobalstatic.h @@ -63,7 +63,7 @@ template union Holder using PlainType = std::remove_cv_t; static constexpr bool ConstructionIsNoexcept = noexcept(QGS::innerFunction(nullptr)); - static inline QBasicAtomicInteger guard = { QtGlobalStatic::Uninitialized }; + Q_CONSTINIT static inline QBasicAtomicInteger guard = { QtGlobalStatic::Uninitialized }; // union's sole member PlainType storage; @@ -144,7 +144,7 @@ protected: new (pointer) QGS_Type ARGS; \ } \ }; } \ - static QGlobalStatic> NAME; \ + Q_CONSTINIT static QGlobalStatic> NAME; \ QT_WARNING_POP /**/ diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 254894961e2..6302fc9d80a 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1096,7 +1096,7 @@ struct QMessagePattern Q_DECLARE_TYPEINFO(QMessagePattern::BacktraceParams, Q_RELOCATABLE_TYPE); #endif -QBasicMutex QMessagePattern::mutex; +Q_CONSTINIT QBasicMutex QMessagePattern::mutex; QMessagePattern::QMessagePattern() { @@ -1750,7 +1750,7 @@ static bool android_default_message_handler(QtMsgType type, static void win_outputDebugString_helper(const QString &message) { const qsizetype maxOutputStringLength = 32766; - static QBasicMutex m; + Q_CONSTINIT static QBasicMutex m; auto locker = qt_unique_lock(m); // fast path: Avoid string copies if one output is enough if (message.length() <= maxOutputStringLength) { @@ -1827,7 +1827,7 @@ static void stderr_message_handler(QtMsgType type, const QMessageLogContext &con #ifdef Q_OS_WASM // Prevent thread cross-talk, which causes Emscripten to log // non-valid UTF-8. FIXME: remove once we upgrade to emsdk > 2.0.30 - static QBasicMutex m; + Q_CONSTINIT static QBasicMutex m; auto locker = qt_unique_lock(m); #endif diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp index 77362c2073e..2dd5d13e536 100644 --- a/src/corelib/io/qfileselector.cpp +++ b/src/corelib/io/qfileselector.cpp @@ -58,7 +58,7 @@ using namespace Qt::StringLiterals; static const char env_override[] = "QT_NO_BUILTIN_SELECTORS"; Q_GLOBAL_STATIC(QFileSelectorSharedData, sharedData); -static QBasicMutex sharedDataMutex; +Q_CONSTINIT static QBasicMutex sharedDataMutex; QFileSelectorPrivate::QFileSelectorPrivate() : QObjectPrivate() diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 9d1e4694bcf..36fc5151648 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -424,7 +424,7 @@ static QString resolveExecutable(const QString &program) { // CFBundle is not reentrant, since CFBundleCreate might return a reference // to a cached bundle object. Protect the bundle calls with a mutex lock. - static QBasicMutex cfbundleMutex; + Q_CONSTINIT static QBasicMutex cfbundleMutex; const auto locker = qt_scoped_lock(cfbundleMutex); QCFType bundle = CFBundleCreate(0, url); // 'executableURL' can be either relative or absolute ... diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 4c28dbca38f..998cfad6811 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -132,7 +132,7 @@ Q_GLOBAL_STATIC(ConfFileCache, unusedCacheFunc) Q_GLOBAL_STATIC(PathHash, pathHashFunc) Q_GLOBAL_STATIC(CustomFormatVector, customFormatVectorFunc) -static QBasicMutex settingsGlobalMutex; +Q_CONSTINIT static QBasicMutex settingsGlobalMutex; static QSettings::Format globalDefaultFormat = QSettings::NativeFormat; diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index e41c1b6df79..42f4af186fc 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -265,8 +265,8 @@ typedef QList QStartUpFuncList; Q_GLOBAL_STATIC(QStartUpFuncList, preRList) typedef QList QVFuncList; Q_GLOBAL_STATIC(QVFuncList, postRList) -static QBasicMutex globalRoutinesMutex; -static bool preRoutinesCalled = false; +Q_CONSTINIT static QBasicMutex globalRoutinesMutex; +Q_CONSTINIT static bool preRoutinesCalled = false; /*! \internal diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp index 974ce7f5e16..cff3efd1cc9 100644 --- a/src/corelib/kernel/qeventdispatcher_glib.cpp +++ b/src/corelib/kernel/qeventdispatcher_glib.cpp @@ -296,7 +296,7 @@ QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context) { #if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 32 if (qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")) { - static QBasicMutex mutex; + Q_CONSTINIT static QBasicMutex mutex; QMutexLocker locker(&mutex); if (!g_thread_supported()) g_thread_init(NULL); diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 70f98e8324f..750f8b541ca 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -149,7 +149,7 @@ static int *queuedConnectionTypes(const QArgumentType *argumentTypes, int argc) return types.release(); } -static QBasicMutex _q_ObjectMutexPool[131]; +Q_CONSTINIT static QBasicMutex _q_ObjectMutexPool[131]; /** * \internal diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 43dcb171848..bb732c44087 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -354,9 +354,9 @@ private: LibraryMap libraryMap; }; -static QBasicMutex qt_library_mutex; -static QLibraryStore *qt_library_data = nullptr; -static bool qt_library_data_once; +Q_CONSTINIT static QBasicMutex qt_library_mutex; +Q_CONSTINIT static QLibraryStore *qt_library_data = nullptr; +Q_CONSTINIT static bool qt_library_data_once; QLibraryStore::~QLibraryStore() { diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index c1491f0f153..dd92cfe354f 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -792,7 +792,7 @@ static const QLocaleData *systemData() one thread. */ { - static QBasicMutex systemDataMutex; + Q_CONSTINIT static QBasicMutex systemDataMutex; systemDataMutex.lock(); if (systemLocaleData.m_language_id == 0) updateSystemPrivate(); diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index 239f463a181..72865d5872a 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -501,8 +501,8 @@ QThreadPool::~QThreadPool() */ QThreadPool *QThreadPool::globalInstance() { - static QPointer theInstance; - static QBasicMutex theMutex; + Q_CONSTINIT static QPointer theInstance; + Q_CONSTINIT static QBasicMutex theMutex; const QMutexLocker locker(&theMutex); if (theInstance.isNull() && !QCoreApplication::closingDown()) diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp index ee8273687bb..369c36e2c83 100644 --- a/src/corelib/thread/qthreadstorage.cpp +++ b/src/corelib/thread/qthreadstorage.cpp @@ -68,7 +68,7 @@ void qtsDebug(const char *fmt, ...) # define DEBUG_MSG if (false)qDebug #endif -static QBasicMutex destructorsMutex; +Q_CONSTINIT static QBasicMutex destructorsMutex; typedef QList DestructorMap; Q_GLOBAL_STATIC(DestructorMap, destructors) diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index 8cb34e254b0..24871e167e0 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -67,7 +67,7 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; #if QT_CONFIG(icu) -static QBasicMutex s_icu_mutex; +Q_CONSTINIT static QBasicMutex s_icu_mutex; #endif /* diff --git a/src/dbus/qdbus_symbols.cpp b/src/dbus/qdbus_symbols.cpp index bd4299809bc..0eccbe669e3 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 7efd94ac776..9ddaf8d4c17 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 bf42736eabc..090862a222f 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() { diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 940f87af9a7..fe0c01e54c6 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -186,7 +186,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, QByteArray suffix; #ifndef QT_NO_IMAGEFORMATPLUGIN - static QBasicMutex mutex; + Q_CONSTINIT static QBasicMutex mutex; const auto locker = qt_scoped_lock(mutex); typedef QMultiMap PluginKeyMap; diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 0935f654eb9..f45cf1fb78f 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -145,79 +145,79 @@ QT_BEGIN_NAMESPACE Q_CORE_EXPORT void qt_call_post_routines(); Q_GUI_EXPORT bool qt_is_tty_app = false; -Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton; -Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier; +Q_CONSTINIT Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton; +Q_CONSTINIT Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier; -QGuiApplicationPrivate::QLastCursorPosition QGuiApplicationPrivate::lastCursorPosition; +Q_CONSTINIT QGuiApplicationPrivate::QLastCursorPosition QGuiApplicationPrivate::lastCursorPosition; -QWindow *QGuiApplicationPrivate::currentMouseWindow = nullptr; +Q_CONSTINIT QWindow *QGuiApplicationPrivate::currentMouseWindow = nullptr; -QString QGuiApplicationPrivate::styleOverride; +Q_CONSTINIT QString QGuiApplicationPrivate::styleOverride; -Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive; +Q_CONSTINIT Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive; -Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = +Q_CONSTINIT Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough; -QPointer QGuiApplicationPrivate::currentDragWindow; +Q_CONSTINIT QPointer QGuiApplicationPrivate::currentDragWindow; -QList QGuiApplicationPrivate::tabletDevicePoints; // TODO remove +Q_CONSTINIT QList QGuiApplicationPrivate::tabletDevicePoints; // TODO remove -QPlatformIntegration *QGuiApplicationPrivate::platform_integration = nullptr; -QPlatformTheme *QGuiApplicationPrivate::platform_theme = nullptr; +Q_CONSTINIT QPlatformIntegration *QGuiApplicationPrivate::platform_integration = nullptr; +Q_CONSTINIT QPlatformTheme *QGuiApplicationPrivate::platform_theme = nullptr; -QList QGuiApplicationPrivate::generic_plugin_list; +Q_CONSTINIT QList QGuiApplicationPrivate::generic_plugin_list; enum ApplicationResourceFlags { ApplicationFontExplicitlySet = 0x2 }; -static unsigned applicationResourceFlags = 0; +Q_CONSTINIT static unsigned applicationResourceFlags = 0; -QIcon *QGuiApplicationPrivate::app_icon = nullptr; +Q_CONSTINIT QIcon *QGuiApplicationPrivate::app_icon = nullptr; -QString *QGuiApplicationPrivate::platform_name = nullptr; -QString *QGuiApplicationPrivate::displayName = nullptr; -QString *QGuiApplicationPrivate::desktopFileName = nullptr; +Q_CONSTINIT QString *QGuiApplicationPrivate::platform_name = nullptr; +Q_CONSTINIT QString *QGuiApplicationPrivate::displayName = nullptr; +Q_CONSTINIT QString *QGuiApplicationPrivate::desktopFileName = nullptr; -QPalette *QGuiApplicationPrivate::app_pal = nullptr; // default application palette +Q_CONSTINIT QPalette *QGuiApplicationPrivate::app_pal = nullptr; // default application palette -Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton; +Q_CONSTINIT Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton; -static int mouseDoubleClickDistance = 0; -static int touchDoubleTapDistance = 0; +Q_CONSTINIT static int mouseDoubleClickDistance = 0; +Q_CONSTINIT static int touchDoubleTapDistance = 0; -QWindow *QGuiApplicationPrivate::currentMousePressWindow = nullptr; +Q_CONSTINIT QWindow *QGuiApplicationPrivate::currentMousePressWindow = nullptr; -static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto; -static Qt::LayoutDirection effective_layout_direction = Qt::LeftToRight; -static bool force_reverse = false; +Q_CONSTINIT static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto; +Q_CONSTINIT static Qt::LayoutDirection effective_layout_direction = Qt::LeftToRight; +Q_CONSTINIT static bool force_reverse = false; -QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr; -int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1; +Q_CONSTINIT QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr; +Q_CONSTINIT int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1; #ifndef QT_NO_CLIPBOARD -QClipboard *QGuiApplicationPrivate::qt_clipboard = nullptr; +Q_CONSTINIT QClipboard *QGuiApplicationPrivate::qt_clipboard = nullptr; #endif -QList QGuiApplicationPrivate::screen_list; +Q_CONSTINIT QList QGuiApplicationPrivate::screen_list; -QWindowList QGuiApplicationPrivate::window_list; -QWindow *QGuiApplicationPrivate::focus_window = nullptr; +Q_CONSTINIT QWindowList QGuiApplicationPrivate::window_list; +Q_CONSTINIT QWindow *QGuiApplicationPrivate::focus_window = nullptr; -static QBasicMutex applicationFontMutex; -QFont *QGuiApplicationPrivate::app_font = nullptr; -QStyleHints *QGuiApplicationPrivate::styleHints = nullptr; -bool QGuiApplicationPrivate::obey_desktop_settings = true; +Q_CONSTINIT static QBasicMutex applicationFontMutex; +Q_CONSTINIT QFont *QGuiApplicationPrivate::app_font = nullptr; +Q_CONSTINIT QStyleHints *QGuiApplicationPrivate::styleHints = nullptr; +Q_CONSTINIT bool QGuiApplicationPrivate::obey_desktop_settings = true; -QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = nullptr; +Q_CONSTINIT QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = nullptr; -qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0; +Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0; -static qreal fontSmoothingGamma = 1.7; +Q_CONSTINIT static qreal fontSmoothingGamma = 1.7; -bool QGuiApplicationPrivate::quitOnLastWindowClosed = true; +Q_CONSTINIT bool QGuiApplicationPrivate::quitOnLastWindowClosed = true; extern void qRegisterGuiVariant(); #if QT_CONFIG(animation) diff --git a/src/gui/kernel/qinputdevice.cpp b/src/gui/kernel/qinputdevice.cpp index 8aea2f6e2ec..841163608bd 100644 --- a/src/gui/kernel/qinputdevice.cpp +++ b/src/gui/kernel/qinputdevice.cpp @@ -264,7 +264,7 @@ QString QInputDevice::seatName() const using InputDevicesList = QList; Q_GLOBAL_STATIC(InputDevicesList, deviceList) -static QBasicMutex devicesMutex; +Q_CONSTINIT static QBasicMutex devicesMutex; /*! Returns a list of all registered input devices (keyboards and pointing devices). diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index 4601746992f..ca54f0155c3 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE -QBasicMutex QColorSpacePrivate::s_lutWriteLock; +Q_CONSTINIT QBasicMutex QColorSpacePrivate::s_lutWriteLock; static QAtomicPointer s_predefinedColorspacePrivates[QColorSpace::ProPhotoRgb] = {}; static void cleanupPredefinedColorspaces() diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index e1d978af11e..29b6eddc801 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1714,7 +1714,7 @@ QNetworkRequest QNetworkAccessManagerPrivate::prepareMultipart(const QNetworkReq */ void QNetworkAccessManagerPrivate::ensureBackendPluginsLoaded() { - static QBasicMutex mutex; + Q_CONSTINIT static QBasicMutex mutex; std::unique_lock locker(mutex); if (!loader()) return; diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp index 97f4a2cba48..9b398d70796 100644 --- a/src/network/kernel/qauthenticator.cpp +++ b/src/network/kernel/qauthenticator.cpp @@ -1574,7 +1574,7 @@ static PSecurityFunctionTableW pSecurityFunctionTable = nullptr; static bool q_SSPI_library_load() { - static QBasicMutex mutex; + Q_CONSTINIT static QBasicMutex mutex; QMutexLocker l(&mutex); if (pSecurityFunctionTable == nullptr) diff --git a/src/network/kernel/qnetworkinformation.cpp b/src/network/kernel/qnetworkinformation.cpp index 836b63bd4bc..626439572a9 100644 --- a/src/network/kernel/qnetworkinformation.cpp +++ b/src/network/kernel/qnetworkinformation.cpp @@ -124,7 +124,7 @@ bool QNetworkInformationPrivate::initializeList() return false; if (!dataHolder()) return false; - static QBasicMutex mutex; + Q_CONSTINIT static QBasicMutex mutex; QMutexLocker initLocker(&mutex); #if QT_CONFIG(library) diff --git a/src/network/ssl/qtlsbackend.cpp b/src/network/ssl/qtlsbackend.cpp index dbfbddc3793..1674c7d706e 100644 --- a/src/network/ssl/qtlsbackend.cpp +++ b/src/network/ssl/qtlsbackend.cpp @@ -91,7 +91,7 @@ public: if (!loader()) return false; - static QBasicMutex mutex; + Q_CONSTINIT static QBasicMutex mutex; const QMutexLocker locker(&mutex); if (backends.size()) return true; diff --git a/src/plugins/platforms/xcb/qxcbeventqueue.cpp b/src/plugins/platforms/xcb/qxcbeventqueue.cpp index 99510d1a421..bd4cff8f89a 100644 --- a/src/plugins/platforms/xcb/qxcbeventqueue.cpp +++ b/src/plugins/platforms/xcb/qxcbeventqueue.cpp @@ -47,8 +47,8 @@ QT_BEGIN_NAMESPACE -static QBasicMutex qAppExiting; -static bool dispatcherOwnerDestructing = false; +Q_CONSTINIT static QBasicMutex qAppExiting; +Q_CONSTINIT static bool dispatcherOwnerDestructing = false; /*! \class QXcbEventQueue diff --git a/src/plugins/tls/openssl/qsslsocket_openssl_symbols.cpp b/src/plugins/tls/openssl/qsslsocket_openssl_symbols.cpp index 27ed594d6dd..c9d788bb3ee 100644 --- a/src/plugins/tls/openssl/qsslsocket_openssl_symbols.cpp +++ b/src/plugins/tls/openssl/qsslsocket_openssl_symbols.cpp @@ -868,9 +868,9 @@ static LoadedOpenSsl loadOpenSsl() } #endif -static QBasicMutex symbolResolveMutex; -static QBasicAtomicInt symbolsResolved = Q_BASIC_ATOMIC_INITIALIZER(false); -static bool triedToResolveSymbols = false; +Q_CONSTINIT static QBasicMutex symbolResolveMutex; +Q_CONSTINIT static QBasicAtomicInt symbolsResolved = Q_BASIC_ATOMIC_INITIALIZER(false); +Q_CONSTINIT static bool triedToResolveSymbols = false; bool q_resolveOpenSslSymbols() {