Skip to content

Commit

Permalink
QVarLengthArray: avoid std::aligned_storage (deprecated in C++23)
Browse files Browse the repository at this point in the history
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:
- cplusplus/papers#197
- wg21.link/p1413

Task-number: QTBUG-99122
Pick-to: 6.3 6.2
Change-Id: I212be7000376c2db33b8cb244a6e862cc4dad544
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
marcmutz committed Dec 15, 2021
1 parent 9440c1a commit 9a7d2a7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/corelib/tools/qvarlengtharray.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ QT_BEGIN_NAMESPACE
template <size_t Size, size_t Align, qsizetype Prealloc>
class QVLAStorage
{
template <size_t> class print;
protected:
~QVLAStorage() = default;

std::aligned_storage_t<Size, Align> 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<print<sizeof(std::aligned_storage_t<Size, Align>[Prealloc])>,
print<sizeof(array)>>);
QT_WARNING_POP
};

class QVLABaseBase
Expand Down

0 comments on commit 9a7d2a7

Please sign in to comment.