Skip to content

Commit

Permalink
Fix QByteArray vs QLatin1StringView operator+() ambiguity
Browse files Browse the repository at this point in the history
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 7b70761.

Task-number: QTBUG-127904
Task-number: QTBUG-127928
Task-number: QTBUG-127931
Change-Id: I92d527890a879263534cda62e30c92c234fb36a7
Reviewed-by: Volker Hilsheimer <[email protected]>
Reviewed-by: Matthias Rauter <[email protected]>
  • Loading branch information
isolovev committed Aug 12, 2024
1 parent b7e13a8 commit 07a0ecf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/corelib/text/qbytearray.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#define LITERAL "some literal"

#define HAS_QTBUG_127928 1

namespace {
#define P +
#include "../qstringbuilder1/stringbuilder.cpp"
Expand Down

0 comments on commit 07a0ecf

Please sign in to comment.