QString: remove op+=(char) and op+=(QChar::SpecialCharacter)
The former messes in bad ways with the overload set (it, fatally, attracts char16_t, e.g.). The latter was probably added in response to ambiguities between (char) and (QChar). While it's harmless now, remove it, since it no longer pulls its weight. The no-ascii warning is now coming from QChar(char), so the protection isn't lost. [ChangeLog][QtCore][QString] The += operators taking char and QChar::SpecialCharacter have been removed as they cause adding a char16_t to QString to call the char overload, losing information. The append() function was not affected. Change-Id: I57116314bcc71c0d9476159513c0c10048239db3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
082eebe6a4
commit
90f864a4c5
@ -5931,22 +5931,6 @@ QString& QString::fill(QChar ch, int size)
|
||||
Appends the string view \a str to this string.
|
||||
*/
|
||||
|
||||
/*! \fn QString &QString::operator+=(char ch)
|
||||
|
||||
\overload operator+=()
|
||||
|
||||
Appends the character \a ch to this string. Note that the character is
|
||||
converted to Unicode using the fromLatin1() function, unlike other 8-bit
|
||||
functions that operate on UTF-8 data.
|
||||
|
||||
You can disable this function by defining \c QT_NO_CAST_FROM_ASCII
|
||||
when you compile your applications. This can be useful if you want
|
||||
to ensure that all user-visible strings go through QObject::tr(),
|
||||
for example.
|
||||
|
||||
\sa QT_NO_CAST_FROM_ASCII
|
||||
*/
|
||||
|
||||
/*! \fn QString &QString::operator+=(QChar ch)
|
||||
|
||||
\overload operator+=()
|
||||
@ -5954,13 +5938,6 @@ QString& QString::fill(QChar ch, int size)
|
||||
Appends the character \a ch to the string.
|
||||
*/
|
||||
|
||||
/*! \fn QString &QString::operator+=(QChar::SpecialCharacter c)
|
||||
|
||||
\overload operator+=()
|
||||
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool operator==(const char *s1, const QString &s2)
|
||||
|
||||
|
@ -570,7 +570,6 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline QString &operator+=(QChar::SpecialCharacter c) { return append(QChar(c)); }
|
||||
#if QT_STRINGVIEW_LEVEL < 2
|
||||
inline QString &operator+=(const QString &s) { return append(s); }
|
||||
inline QString &operator+=(const QStringRef &s) { return append(s); }
|
||||
@ -859,8 +858,6 @@ public:
|
||||
{ return append(QString::fromUtf8(s)); }
|
||||
inline QT_ASCII_CAST_WARN QString &operator+=(const QByteArray &s)
|
||||
{ return append(QString::fromUtf8(s)); }
|
||||
inline QT_ASCII_CAST_WARN QString &operator+=(char c)
|
||||
{ return append(QChar::fromLatin1(c)); }
|
||||
|
||||
inline QT_ASCII_CAST_WARN bool operator==(const char *s) const;
|
||||
inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const;
|
||||
|
@ -447,10 +447,9 @@ private slots:
|
||||
void operator_pluseq_qchar_data() { operator_pluseq_data(true); }
|
||||
void operator_pluseq_qbytearray() { operator_pluseq_impl<QByteArray>(); }
|
||||
void operator_pluseq_qbytearray_data() { operator_pluseq_data(); }
|
||||
void operator_pluseq_char() { operator_pluseq_impl<char, QString &(QString::*)(char)>(); }
|
||||
void operator_pluseq_char_data() { operator_pluseq_data(true); }
|
||||
void operator_pluseq_charstar() { operator_pluseq_impl<const char *, QString &(QString::*)(const char *)>(); }
|
||||
void operator_pluseq_charstar_data() { operator_pluseq_data(); }
|
||||
void operator_pluseq_special_cases();
|
||||
void operator_pluseq_bytearray_special_cases_data();
|
||||
void operator_pluseq_bytearray_special_cases();
|
||||
|
||||
@ -2703,6 +2702,17 @@ void tst_QString::append_bytearray_special_cases()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QString::operator_pluseq_special_cases()
|
||||
{
|
||||
{
|
||||
QString a;
|
||||
a += QChar::CarriageReturn;
|
||||
a += '\r';
|
||||
a += u'\x1111';
|
||||
QCOMPARE(a, QStringView(u"\r\r\x1111"));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QString::operator_pluseq_data(bool emptyIsNoop)
|
||||
{
|
||||
append_data(emptyIsNoop);
|
||||
|
Loading…
Reference in New Issue
Block a user