From c581474dfbfcb517573d8870cbbdc53f579e09cc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 10 Feb 2023 14:25:20 +0100 Subject: [PATCH] QVarLengthArray: clear() is not resize(0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The latter needs the value_type to be default-constructible, which shouldn't be required to clear() a container. Use std::destroy_n() instead. [ChangeLog][QtCore][QVarLengthArray] clear() no longer requires the value_type to be default-constructible. Manual conflict resolutions: - No QVLAStorage/Base/QVarLengthArray split in 6.2, yet Change-Id: I806de8f3826b50c0bd38156892c3afeb15f13ac9 Reviewed-by: Thiago Macieira (cherry picked from commit fbfee2d7c59a7c6cd17ae7a3f63f983b9f3316f5) Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qvarlengtharray.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 50b80d9f54e..67d8bdcdd16 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -183,7 +183,12 @@ public: } inline bool isEmpty() const { return (s == 0); } inline void resize(qsizetype size); - inline void clear() { resize(0); } + void clear() + { + if constexpr (QTypeInfo::isComplex) + std::destroy_n(data(), size()); + s = 0; + } inline void squeeze(); inline qsizetype capacity() const { return a; }