From 2e1699d3b032ec5940c7e5a3e8dd6f1157c208a9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 18 Jul 2022 10:46:16 +0200 Subject: [PATCH] QCollator: port compare(ptr, n, ptr, n) to qsizetype While the function is inline, the class is exported wholesale, so the function forms part of the ABI on Windows (but not Unix), so we must overload, can't replace. To avoid ambiguities where users pass different integer types as the lengths of the LHS and RHS strings, QT_REMOVED_SINCE the old overload. Since the removed function has an inline definition, it suffices to just include the header into the corresponding QT_REMOVED_SINCE section of the removed_api.cpp file, to elegantly solve the BiC problem only for those platforms (MSVC) where it matters. Task-number: QTBUG-103531 Change-Id: I74d446f08fcd6247a2ec44575b8afef8d014c3b5 Reviewed-by: Thiago Macieira (cherry picked from commit 749b2df889ac94c106e59b915ec5862384978878) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/compat/removed_api.cpp | 2 ++ src/corelib/text/qcollator.cpp | 5 ++++- src/corelib/text/qcollator.h | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index d56ea9f43af..c2cff280011 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -169,6 +169,8 @@ QCalendar::QCalendar(QStringView name) QCalendar::QCalendar(QLatin1StringView name) : QCalendar(QAnyStringView{name}) {} +#include "qcollator.h" // inline function compare(ptr, n, ptr, n) (for MSVC) + #if QT_CONFIG(future) #include "qfutureinterface.h" diff --git a/src/corelib/text/qcollator.cpp b/src/corelib/text/qcollator.cpp index 4db6950f762..34c14a89b4e 100644 --- a/src/corelib/text/qcollator.cpp +++ b/src/corelib/text/qcollator.cpp @@ -318,7 +318,7 @@ bool QCollator::ignorePunctuation() const */ /*! - \fn int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const + \fn int QCollator::compare(const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const \overload \since 5.2 @@ -327,6 +327,9 @@ bool QCollator::ignorePunctuation() const Returns an integer less than, equal to, or greater than zero depending on whether \a s1 sorts before, with or after \a s2. + + \note In Qt versions prior to 6.4, the length arguments were of type + \c{int}, not \c{qsizetype}. */ #endif // QT_STRINGVIEW_LEVEL < 2 diff --git a/src/corelib/text/qcollator.h b/src/corelib/text/qcollator.h index 315ce43e9b5..3a9824448b7 100644 --- a/src/corelib/text/qcollator.h +++ b/src/corelib/text/qcollator.h @@ -68,8 +68,12 @@ public: #if QT_STRINGVIEW_LEVEL < 2 int compare(const QString &s1, const QString &s2) const { return compare(QStringView(s1), QStringView(s2)); } +#if QT_CORE_REMOVED_SINCE(6, 4) && QT_POINTER_SIZE != 4 int compare(const QChar *s1, int len1, const QChar *s2, int len2) const { return compare(QStringView(s1, len1), QStringView(s2, len2)); } +#endif + int compare(const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const + { return compare(QStringView(s1, len1), QStringView(s2, len2)); } bool operator()(const QString &s1, const QString &s2) const { return compare(s1, s2) < 0; }