From ae515c3f2eb8ac83af99fb6fbcdb3080dd4a90a7 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 18 Jul 2024 21:25:03 +0200 Subject: [PATCH] Fix signature of QDebug::toString() (again) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are zero QDebug operators that take an rvalue RHS, so there's no need to make toString() perfectly forwarding. It just causes four¹ different versions of the identical function to be instantiated. Not all compilers can merge the binary representations and those that try, violate the standard (same address for different functions). ¹ {rvalue, lvalue} × {const, non-const} Fix by taking by cref. Amends 40976532158fc49be45bb976455f48e98f9690cf. [ChangeLog][Potentially Source-Incompatible Changes][QtCore][QDebug] The toString() static function no longer allows the called operator<<() to modify the argument. No Qt-provided operator<<() does that, and operators that do are probably buggy. Change-Id: Iac1ee9d29f93fd4840b75ffe363d354a2d19a96e Reviewed-by: Thiago Macieira (cherry picked from commit 13244eef6c913bb7f27cd8fbf459f5dfe9a0ed21) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qdebug.cpp | 2 +- src/corelib/io/qdebug.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 64b693fea51..70832c3dbcb 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -996,7 +996,7 @@ QDebug &QDebug::resetFormat() */ /*! - \fn template QString QDebug::toString(T &&object) + \fn template QString QDebug::toString(const T &object) \since 6.0 \include qdebug-toString.qdocinc diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 44c3dea804b..6d48c7853d4 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -224,11 +224,11 @@ public: #endif // QT_SUPPORTS_INT128 template - static QString toString(T &&object) + static QString toString(const T &object) { QString buffer; QDebug stream(&buffer); - stream.nospace() << std::forward(object); + stream.nospace() << object; return buffer; } };