summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-05-07 12:53:23 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-05-07 20:47:44 +0200
commit32f1847e1e3f13dc64baf8e90e7ce0a360c71aba (patch)
treef0e30af86f26e25f1397de08eb98da3b021cf66f
parentd8e03bb02d93f9eb843923063c13162ce10079e0 (diff)
QRandomGenerator: port away from std::aligned_storage
It's deprecated in C++23. Just use an explicitly-aligned char array directly, wrapped in a struct to avoid decays to char*. Task-number: QTBUG-99122 Pick-to: 6.3 6.2 Change-Id: Ic5807f0161cd9f360baa07464988bc48b9679f64 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/global/qrandom.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp
index daf0a46387..7ea983540e 100644
--- a/src/corelib/global/qrandom.cpp
+++ b/src/corelib/global/qrandom.cpp
@@ -353,16 +353,17 @@ struct QRandomGenerator::SystemAndGlobalGenerators
// the state in case another thread tries to lock the mutex. It's not
// a common scenario, but since sizeof(QRandomGenerator) >= 2560, the
// overhead is actually acceptable.
- // 2) We use both alignas and std::aligned_storage<..., 64> because
- // some implementations of std::aligned_storage can't align to more
- // than a primitive type's alignment.
+ // 2) We use both alignas(T) and alignas(64) because some implementations
+ // can't align to more than a primitive type's alignment.
// 3) We don't store the entire system QRandomGenerator, only the space
// used by the QRandomGenerator::type member. This is fine because we
// (ab)use the common initial sequence exclusion to aliasing rules.
QBasicMutex globalPRNGMutex;
struct ShortenedSystem { uint type; } system_;
SystemGenerator sys;
- alignas(64) std::aligned_storage<sizeof(QRandomGenerator64), 64>::type global_;
+ alignas(64) struct {
+ alignas(QRandomGenerator64) uchar data[sizeof(QRandomGenerator64)];
+ } global_;
constexpr SystemAndGlobalGenerators()
: globalPRNGMutex{}, system_{0}, sys{}, global_{}