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. Change-Id: I0225a4533841e5b433a3d9781b2642c084f775ab Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 0f447e875da42f62cf8533e78435b7b24ca41ae0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
2822ac9c91
commit
b4fe493a79
@ -259,6 +259,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;
|
||||
|
||||
@ -655,7 +656,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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user