diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index 40205cae9c..03acaa50d8 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -100,6 +100,13 @@ struct IsContainerCompatibleWithQByteArrayView, QByteArrayView>>>>> : std::true_type {}; +// Used by QLatin1String too +template +static constexpr qsizetype lengthHelperPointer(const Char *data) noexcept +{ + return qsizetype(std::char_traits::length(data)); +} + } // namespace QtPrivate class Q_CORE_EXPORT QByteArrayView @@ -138,12 +145,6 @@ private: typename std::enable_if_t::value, bool>; - template - static constexpr qsizetype lengthHelperPointer(const Char *data) noexcept - { - return qsizetype(std::char_traits::length(data)); - } - template static constexpr qsizetype lengthHelperContainer(const Container &c) noexcept { @@ -185,7 +186,7 @@ public: template = true> constexpr QByteArrayView(const Pointer &data) noexcept : QByteArrayView( - data, data ? lengthHelperPointer(data) : 0) {} + data, data ? QtPrivate::lengthHelperPointer(data) : 0) {} #endif #ifdef Q_QDOC diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 1c95b038c6..350659ed46 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -85,7 +86,8 @@ class QLatin1String public: constexpr inline QLatin1String() noexcept : m_size(0), m_data(nullptr) {} constexpr QLatin1String(std::nullptr_t) noexcept : QLatin1String() {} - constexpr inline explicit QLatin1String(const char *s) noexcept : m_size(s ? qsizetype(strlen(s)) : 0), m_data(s) {} + constexpr inline explicit QLatin1String(const char *s) noexcept + : m_size(s ? qsizetype(QtPrivate::lengthHelperPointer(s)) : 0), m_data(s) {} constexpr explicit QLatin1String(const char *f, const char *l) : QLatin1String(f, qsizetype(l - f)) {} constexpr inline explicit QLatin1String(const char *s, qsizetype sz) noexcept : m_size(sz), m_data(s) {}