summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-02-14 09:17:45 +0100
committerMarc Mutz <marc.mutz@qt.io>2023-03-01 20:10:58 +0000
commit0f447e875da42f62cf8533e78435b7b24ca41ae0 (patch)
tree045c77f2bcce00eaef27039dc52c41ea86708038
parentb37b820ce8801613139241036d15baa581a6a403 (diff)
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>
-rw-r--r--src/corelib/tools/qvarlengtharray.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index a47530219f..8840f7cabc 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -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));