From 32f1847e1e3f13dc64baf8e90e7ce0a360c71aba Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 7 May 2022 12:53:23 +0200 Subject: [PATCH] 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 --- src/corelib/global/qrandom.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp index daf0a463875..7ea983540e5 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::type global_; + alignas(64) struct { + alignas(QRandomGenerator64) uchar data[sizeof(QRandomGenerator64)]; + } global_; constexpr SystemAndGlobalGenerators() : globalPRNGMutex{}, system_{0}, sys{}, global_{}