summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qapplicationstatic.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qapplicationstatic.h')
-rw-r--r--src/corelib/kernel/qapplicationstatic.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/corelib/kernel/qapplicationstatic.h b/src/corelib/kernel/qapplicationstatic.h
index d2e050a911..2f2cab9174 100644
--- a/src/corelib/kernel/qapplicationstatic.h
+++ b/src/corelib/kernel/qapplicationstatic.h
@@ -9,6 +9,8 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/qglobalstatic.h>
+#include <new>
+
QT_BEGIN_NAMESPACE
namespace QtGlobalStatic {
@@ -17,7 +19,7 @@ template <typename QAS> struct ApplicationHolder
using Type = typename QAS::QAS_Type;
using PlainType = std::remove_cv_t<Type>;
- Q_CONSTINIT static inline std::aligned_union_t<1, PlainType> storage = {};
+ Q_CONSTINIT static inline struct { alignas(Type) unsigned char data[sizeof(Type)]; } storage = {};
Q_CONSTINIT static inline QBasicAtomicInteger<qint8> guard = { QtGlobalStatic::Uninitialized };
Q_CONSTINIT static inline QBasicMutex mutex {};
@@ -36,7 +38,7 @@ template <typename QAS> struct ApplicationHolder
static PlainType *realPointer()
{
- return reinterpret_cast<PlainType *>(&storage);
+ return std::launder(reinterpret_cast<PlainType *>(&storage));
}
// called from QGlobalStatic::instance()
@@ -46,7 +48,7 @@ template <typename QAS> struct ApplicationHolder
return realPointer();
QMutexLocker locker(&mutex);
if (guard.loadRelaxed() == QtGlobalStatic::Uninitialized) {
- QAS::innerFunction(realPointer());
+ QAS::innerFunction(&storage);
QObject::connect(QCoreApplication::instance(), &QObject::destroyed, reset);
guard.storeRelaxed(QtGlobalStatic::Initialized);
}