From 07a0ecf81fb94a990573df3f51c641e180924892 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Mon, 12 Aug 2024 12:16:32 +0200 Subject: [PATCH] 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 Reviewed-by: Matthias Rauter --- src/corelib/text/qbytearray.h | 2 ++ .../text/qstringbuilder/qstringbuilder6/tst_qstringbuilder6.cpp | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index f6df2d30141..4f4bb6309bd 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -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}; diff --git a/tests/auto/corelib/text/qstringbuilder/qstringbuilder6/tst_qstringbuilder6.cpp b/tests/auto/corelib/text/qstringbuilder/qstringbuilder6/tst_qstringbuilder6.cpp index 5393ec2b905..d766ae04a05 100644 --- a/tests/auto/corelib/text/qstringbuilder/qstringbuilder6/tst_qstringbuilder6.cpp +++ b/tests/auto/corelib/text/qstringbuilder/qstringbuilder6/tst_qstringbuilder6.cpp @@ -20,8 +20,6 @@ #define LITERAL "some literal" -#define HAS_QTBUG_127928 1 - namespace { #define P + #include "../qstringbuilder1/stringbuilder.cpp"