From 50a0c4f3ce615a7eacced3f68f6fdd5dc61c9cff Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 6 Dec 2022 10:51:48 +0100 Subject: [PATCH] QString: fix append/prepend/insert/op+= with QT_RESTRICTED_CAST_FROM_ASCII Since adding the QUtf8StringView overloads, calling these overload sets with const char string literals became ambiguous in QT_RESTRICTED_CAST_FROM_ASCII builds (both QString and QUtf8StringView are a match). Fix by providing the same templated overloads that QT_RESTRICTED_CAST_FROM_ASCII enables for QString construction and assignment for append/prepend/insert/op+=, too. Incidentally, this makes these operations much faster than when they constructed a temporary QString. Change-Id: Ie9b38fc80cc00e142e094dab716938c6fda41ba1 Reviewed-by: hjk Reviewed-by: Thiago Macieira Reviewed-by: Alessandro Portale Reviewed-by: Qt CI Bot --- src/corelib/text/qstring.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 5f54b198fb6..62f0e078eed 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -717,6 +717,17 @@ public: inline QString &operator+=(QLatin1StringView s) { return append(s); } QString &operator+=(QUtf8StringView s) { return append(s); } +#if defined(QT_RESTRICTED_CAST_FROM_ASCII) + template + QString &insert(qsizetype i, const char (&ch)[N]) { return insert(i, QUtf8StringView(ch)); } + template + QString &append(const char (&ch)[N]) { return append(QUtf8StringView(ch)); } + template + QString &prepend(const char (&ch)[N]) { return prepend(QUtf8StringView(ch)); } + template + QString &operator+=(const char (&ch)[N]) { return append(QUtf8StringView(ch)); } +#endif + QString &remove(qsizetype i, qsizetype len); QString &remove(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &remove(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive);