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<QStringView,QStringView>'
qstringtokenizer.h(232): note: see declaration of
    'QStringTokenizer<QStringView,QStringView>'
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 <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Matthias Rauter 2025-04-09 14:16:25 +02:00
parent 8f89bbaf8e
commit eabbc15a5b

View File

@ -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 <typename String>
constexpr qsizetype size(const String &s) noexcept { return static_cast<qsizetype>(s.size()); }
constexpr qsizetype tokenSize(const String &s) noexcept { return static_cast<qsizetype>(s.size()); }
template <typename String> struct ViewForImpl {};
template <> struct ViewForImpl<QStringView> { using type = QStringView; };
@ -386,7 +386,7 @@ auto QStringTokenizerBase<Haystack, Needle>::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 {