From 9a7d2a7acf3d12bfc56581b5b5568c8cf92e0b7a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 14 Dec 2021 17:40:06 +0100 Subject: [PATCH] QVarLengthArray: avoid std::aligned_storage (deprecated in C++23) Add some scaffolding to prevent us from running into BC issues due to the underspecified nature of std::aligned_storage. Qt 5.15 uses a union { char[], double, qint64 } instead of std::aligned_storage, so doesn't need the fix. References: - https://github.com/cplusplus/papers/issues/197 - wg21.link/p1413 Task-number: QTBUG-99122 Pick-to: 6.3 6.2 Change-Id: I212be7000376c2db33b8cb244a6e862cc4dad544 Reviewed-by: Thiago Macieira --- src/corelib/tools/qvarlengtharray.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index a810f00b30..fd3d4ffbf2 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -65,10 +65,18 @@ QT_BEGIN_NAMESPACE template class QVLAStorage { + template class print; protected: ~QVLAStorage() = default; - std::aligned_storage_t array[Prealloc]; + alignas(Align) char array[Prealloc * (Align > Size ? Align : Size)]; + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED + // ensure we maintain BC: std::aligned_storage_t was only specified by a + // minimum size, but for BC we need the substitution to be exact in size: + static_assert(std::is_same_v[Prealloc])>, + print>); + QT_WARNING_POP }; class QVLABaseBase