From eabbc15a5b0cb1b1866778fa014bd599d38f1695 Mon Sep 17 00:00:00 2001 From: Matthias Rauter Date: Wed, 9 Apr 2025 14:16:25 +0200 Subject: [PATCH] Rename QtPrivate::Tok::size to tokenSize Using MSVC 19.43 in C++20 mode leads to a compile error in tst_qstringview. MSVC interprets QStringTokenizer as std::ranges::sized_range because it found size() in the namespace QtPrivate::Tok. QStringTokenizer is derived from a class in that namespace. Naturally this leads to a compile error because QStringTokenizer has no size member function as required in QtPrivate::Tok::size(): qstringtokenizer.h(118): error C2039: 'size': is not a member of 'QStringTokenizer' qstringtokenizer.h(232): note: see declaration of 'QStringTokenizer' qstringtokenizer.h(118): note: the template instantiation context (the oldest one first) is tst_qstringview.cpp(680): note: see reference to function template instantiation ... The problem can be avoided by renaming QtPrivate::Tok::size() to tokenSize. MSVC 19.43 interprets QStringTokenizer as std::ranges::range that do not need the size() member function. Pick-to: 6.9 6.8 Change-Id: Ib94db8e4d840a143bbf693c89e3714e1528a0267 Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira --- src/corelib/text/qstringtokenizer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/text/qstringtokenizer.h b/src/corelib/text/qstringtokenizer.h index 532724306ee..3925054580d 100644 --- a/src/corelib/text/qstringtokenizer.h +++ b/src/corelib/text/qstringtokenizer.h @@ -113,9 +113,9 @@ QT_END_INCLUDE_NAMESPACE namespace QtPrivate { namespace Tok { - constexpr qsizetype size(QChar) noexcept { return 1; } + constexpr qsizetype tokenSize(QChar) noexcept { return 1; } template - constexpr qsizetype size(const String &s) noexcept { return static_cast(s.size()); } + constexpr qsizetype tokenSize(const String &s) noexcept { return static_cast(s.size()); } template struct ViewForImpl {}; template <> struct ViewForImpl { using type = QStringView; }; @@ -386,7 +386,7 @@ auto QStringTokenizerBase::next(tokenizer_state state) const n if (state.end >= 0) { // token separator found => return intermediate element: result = m_haystack.sliced(state.start, state.end - state.start); - const auto ns = QtPrivate::Tok::size(m_needle); + const auto ns = QtPrivate::Tok::tokenSize(m_needle); state.start = state.end + ns; state.extra = (ns == 0 ? 1 : 0); } else {