From 6d5e39f4756945b8ada74d745bd949856c1b17f9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 29 Aug 2024 15:02:23 +0200 Subject: [PATCH] Make Container::max_size() non-static member functions ... as is required by the standard. We have already found that QAnyStringView::max_size() can also not be static (because the size depends on the charset of the contained data), so we have a second reason (besides STL compatibility) to change the current static into non-static max_size() member functions: Qt consistency. Found in API-Review. Amends 7ce6920aacfcba485cd8017e01c6aeb324292e75. Pick-to: 6.8 Fixes: QTBUG-128450 Change-Id: Id5ee3fec82bc557bd83b6843838ccdd753442cd0 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Ivan Solovev --- src/corelib/text/qbytearray.cpp | 2 +- src/corelib/text/qbytearray.h | 3 +-- src/corelib/text/qstring.cpp | 2 +- src/corelib/text/qstring.h | 2 +- src/corelib/tools/qlist.h | 2 +- src/corelib/tools/qlist.qdoc | 2 +- src/corelib/tools/qvarlengtharray.h | 5 +++-- src/corelib/tools/qvarlengtharray.qdoc | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 3ee9d08b00a..a0d633076bf 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -1420,7 +1420,7 @@ QByteArray &QByteArray::operator=(const char *str) \sa isEmpty(), resize() */ -/*! \fn qsizetype QByteArray::max_size() +/*! \fn qsizetype QByteArray::max_size() const \fn qsizetype QByteArray::maxSize() \since 6.8 diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index e9205f0c2f1..f6d626e9a49 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -482,8 +482,7 @@ public: void shrink_to_fit() { squeeze(); } iterator erase(const_iterator first, const_iterator last); inline iterator erase(const_iterator it) { return erase(it, it + 1); } - - static constexpr qsizetype max_size() noexcept + constexpr qsizetype max_size() const noexcept { return maxSize(); } diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index f596619dfd7..077d9accded 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -6412,7 +6412,7 @@ QString& QString::fill(QChar ch, qsizetype size) */ /*! - \fn qsizetype QString::max_size() + \fn qsizetype QString::max_size() const \fn qsizetype QString::maxSize() \since 6.8 diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 11ac4911dc4..fc4892d5c11 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -969,7 +969,7 @@ public: void shrink_to_fit() { squeeze(); } iterator erase(const_iterator first, const_iterator last); inline iterator erase(const_iterator it) { return erase(it, it + 1); } - static constexpr qsizetype max_size() noexcept + constexpr qsizetype max_size() const noexcept { return maxSize(); } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index b8bc8774d45..353765ea291 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -691,7 +691,7 @@ public: inline reference back() { return last(); } inline const_reference back() const noexcept { return last(); } void shrink_to_fit() { squeeze(); } - static constexpr qsizetype max_size() noexcept + constexpr qsizetype max_size() const noexcept { return maxSize(); } diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc index 74da71896b6..19b10fde4d1 100644 --- a/src/corelib/tools/qlist.qdoc +++ b/src/corelib/tools/qlist.qdoc @@ -1332,7 +1332,7 @@ returns \c false. */ -/*! \fn template qsizetype QList::max_size() +/*! \fn template qsizetype QList::max_size() const \fn template qsizetype QList::maxSize() \since 6.8 diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 577a5b193e2..66c8e0bd134 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -189,7 +189,7 @@ public: // -1 to deal with the pointer one-past-the-end return (QtPrivate::MaxAllocSize / sizeof(T)) - 1; } - static constexpr qsizetype max_size() noexcept + constexpr qsizetype max_size() const noexcept { return maxSize(); } @@ -409,9 +409,10 @@ public: #ifdef Q_QDOC inline qsizetype size() const { return this->s; } static constexpr qsizetype maxSize() noexcept { return QVLABase::maxSize(); } - static constexpr qsizetype max_size() noexcept { return QVLABase::max_size(); } + constexpr qsizetype max_size() const noexcept { return QVLABase::max_size(); } #endif using Base::size; + using Base::max_size; inline qsizetype count() const { return size(); } inline qsizetype length() const { return size(); } inline T &first() diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index 8305f495360..b17aedc5335 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -140,7 +140,7 @@ \sa isEmpty(), resize() */ -/*! \fn template qsizetype QVarLengthArray::max_size() +/*! \fn template qsizetype QVarLengthArray::max_size() const \fn template qsizetype QVarLengthArray::maxSize() \since 6.8