diff --git a/src/corelib/text/qstringliteral.h b/src/corelib/text/qstringliteral.h index d86e6eafd9..d9804b31d6 100644 --- a/src/corelib/text/qstringliteral.h +++ b/src/corelib/text/qstringliteral.h @@ -56,14 +56,24 @@ QT_BEGIN_NAMESPACE // core language feature, so just use u"" here unconditionally: #define QT_UNICODE_LITERAL(str) u"" str -#define QStringLiteral(str) \ - (QString(QStringPrivate(nullptr, \ - const_cast(QT_UNICODE_LITERAL(str)), \ - sizeof(QT_UNICODE_LITERAL(str))/2 - 1))) \ - /**/ using QStringPrivate = QArrayDataPointer; +namespace QtPrivate { +template +static Q_ALWAYS_INLINE QStringPrivate qMakeStringPrivate(const char16_t (&literal)[N]) +{ + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) + auto str = const_cast(literal); + return { nullptr, str, N - 1 }; +} +} + +#define QStringLiteral(str) \ + (QString(QtPrivate::qMakeStringPrivate(QT_UNICODE_LITERAL(str)))) \ + /**/ + + QT_END_NAMESPACE #endif // QSTRINGLITERAL_H