From b4fe493a795cbb22650a35903e67202569187c72 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. Change-Id: I0225a4533841e5b433a3d9781b2642c084f775ab Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit 0f447e875da42f62cf8533e78435b7b24ca41ae0) Reviewed-by: Qt Cherry-pick Bot --- 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 d8dbe65b05c..c34a2b6f4e4 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -259,6 +259,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; @@ -655,7 +656,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));