From 0f447e875da42f62cf8533e78435b7b24ca41ae0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 14 Feb 2023 09:17:45 +0100 Subject: [PATCH] QVarLengthArray: move a static_assert() to the correct place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/tools/qvarlengtharray.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; using Storage = QVLAStorage; + static_assert(Prealloc > 0, "QVarLengthArray Prealloc must be greater than 0."); static_assert(std::is_nothrow_destructible_v, "Types with throwing destructors are not supported in Qt containers."); using Base::verify; @@ -673,7 +674,6 @@ template Q_INLINE_TEMPLATE QVarLengthArray::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));