From c54fb03446f0b4c6f6492d0bfe459033ea480fe1 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 14 Dec 2021 16:40:19 -0300 Subject: QGlobalStatic: don't use a std::aligned_union if we can be a union Simplifies further the code with C++11 unrestricted unions. Pick-to: 6.3 Task-number: QTBUG-99122 Change-Id: Ib42b3adc93bf4d43bd55fffd16c0b6677441bf55 Reviewed-by: Marc Mutz --- src/corelib/global/qglobalstatic.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/corelib/global/qglobalstatic.h') 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 struct Holder +template union Holder { using Type = typename QGS::QGS_Type; using PlainType = std::remove_cv_t; static constexpr bool ConstructionIsNoexcept = noexcept(QGS::innerFunction(nullptr)); - std::aligned_union_t<1, PlainType> storage; static inline QBasicAtomicInteger guard = { QtGlobalStatic::Uninitialized }; + // union's sole member + PlainType storage; + Holder() noexcept(ConstructionIsNoexcept) { QGS::innerFunction(pointer()); @@ -81,7 +83,7 @@ template struct Holder PlainType *pointer() noexcept { - return reinterpret_cast(&storage); + return &storage; } Q_DISABLE_COPY_MOVE(Holder) -- cgit v1.2.3