Fix QByteArray vs QLatin1StringView operator+() ambiguity

After the operator=() overloads for QBA vs QBAV were added, the
concatenation of QL1SV vs QBA became ambiguous, because both QBAV and
QString can be constructed from QL1SV.
Mark the new operators as Q_WEAK_OVERLOADs to avoid the ambiguity.

The other possible fix would be to introduce the whole set of
operator+() overloads for QL1SV, but that includes overloads with QBAV,
QBA, and const char *, so I decided to choose the approach that
requires less changes.

Amends 7b707610629d4a2c7bbd3884c3992c913efaba9c.

Task-number: QTBUG-127904
Task-number: QTBUG-127928
Task-number: QTBUG-127931
Change-Id: I92d527890a879263534cda62e30c92c234fb36a7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
This commit is contained in:
Ivan Solovev 2024-08-12 12:16:32 +02:00
parent b7e13a82a7
commit 07a0ecf81f
2 changed files with 2 additions and 2 deletions

View File

@ -684,11 +684,13 @@ inline QByteArray operator+(const char *a1, const QByteArray &a2)
{ return QByteArray(a1) += a2; }
inline QByteArray operator+(char a1, const QByteArray &a2)
{ return QByteArray(&a1, 1) += a2; }
Q_WEAK_OVERLOAD
inline QByteArray operator+(const QByteArray &lhs, QByteArrayView rhs)
{
QByteArray tmp{lhs.size() + rhs.size(), Qt::Uninitialized};
return tmp.assign(lhs).append(rhs);
}
Q_WEAK_OVERLOAD
inline QByteArray operator+(QByteArrayView lhs, const QByteArray &rhs)
{
QByteArray tmp{lhs.size() + rhs.size(), Qt::Uninitialized};

View File

@ -20,8 +20,6 @@
#define LITERAL "some literal"
#define HAS_QTBUG_127928 1
namespace {
#define P +
#include "../qstringbuilder1/stringbuilder.cpp"