QVarLengthArray: move a static_assert() to the correct place

Having the Prealloc > 0 assertion only in the QVLA(qsizetype) ctor
makes no sense. Prealloc > 0 is mandated by the class as a whole, not
that particular ctor, so we shouldn't delay the assertion to the
instantiation of this ctor.

Move it to class scope instead, alongside the assertion for
nothrow-destructible.

Pick-to: 6.5
Change-Id: I0225a4533841e5b433a3d9781b2642c084f775ab
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2023-02-14 09:17:45 +01:00
parent b37b820ce8
commit 0f447e875d

View File

@ -268,6 +268,7 @@ class QVarLengthArray
friend class QVarLengthArray;
using Base = QVLABase<T>;
using Storage = QVLAStorage<sizeof(T), alignof(T), Prealloc>;
static_assert(Prealloc > 0, "QVarLengthArray Prealloc must be greater than 0.");
static_assert(std::is_nothrow_destructible_v<T>, "Types with throwing destructors are not supported in Qt containers.");
using Base::verify;
@ -673,7 +674,6 @@ template <class T, qsizetype Prealloc>
Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype asize)
{
this->s = asize;
static_assert(Prealloc > 0, "QVarLengthArray Prealloc must be greater than 0.");
Q_ASSERT_X(size() >= 0, "QVarLengthArray::QVarLengthArray()", "Size must be greater than or equal to 0.");
if (size() > Prealloc) {
this->ptr = malloc(size() * sizeof(T));