From 8bb9290b72b379c9af6ae99b9f9b66235fd99675 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 10 Feb 2023 14:25:20 +0100 Subject: QVarLengthArray: clear() is not resize(0) 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. Change-Id: I806de8f3826b50c0bd38156892c3afeb15f13ac9 Reviewed-by: Thiago Macieira (cherry picked from commit fbfee2d7c59a7c6cd17ae7a3f63f983b9f3316f5) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qvarlengtharray.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index bd38e2dcc1..9fa8990dbb 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -172,6 +172,13 @@ public: template qsizetype removeIf(Predicate pred); + void clear() + { + if constexpr (QTypeInfo::isComplex) + std::destroy_n(data(), size()); + s = 0; + } + iterator erase(const_iterator begin, const_iterator end); iterator erase(const_iterator pos) { return erase(pos, pos + 1); } @@ -400,7 +407,10 @@ public: #endif void resize(qsizetype sz, const T &v) { Base::resize_impl(Prealloc, this->array, sz, v); } + using Base::clear; +#ifdef Q_QDOC inline void clear() { resize(0); } +#endif void squeeze() { reallocate(size(), size()); } using Base::capacity; -- cgit v1.2.1