diff options
Diffstat (limited to 'src/corelib/global/qglobalstatic.h')
-rw-r--r-- | src/corelib/global/qglobalstatic.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h index 01e06e5234..cf96e5ae8e 100644 --- a/src/corelib/global/qglobalstatic.h +++ b/src/corelib/global/qglobalstatic.h @@ -57,15 +57,17 @@ enum GuardValues { Initializing = 1 }; -template <typename QGS> struct Holder +template <typename QGS> union Holder { using Type = typename QGS::QGS_Type; using PlainType = std::remove_cv_t<Type>; static constexpr bool ConstructionIsNoexcept = noexcept(QGS::innerFunction(nullptr)); - std::aligned_union_t<1, PlainType> storage; static inline QBasicAtomicInteger<qint8> guard = { QtGlobalStatic::Uninitialized }; + // union's sole member + PlainType storage; + Holder() noexcept(ConstructionIsNoexcept) { QGS::innerFunction(pointer()); @@ -81,7 +83,7 @@ template <typename QGS> struct Holder PlainType *pointer() noexcept { - return reinterpret_cast<PlainType *>(&storage); + return &storage; } Q_DISABLE_COPY_MOVE(Holder) |