From 6065ed994868cf3abefd3f25efc057955e23f996 Mon Sep 17 00:00:00 2001 From: Mate Barany Date: Mon, 22 Jul 2024 16:30:12 +0200 Subject: [PATCH] Pass QSslError::SslError by value It is a small and trivially copyable type. As a drive-by, make the operator a hidden friend. Found by an Axivion scan. [ChangeLog][Potentially Source-Incompatible Changes][QtNetwork] Made the QSslError::SslError QDebug operator<< a hidden friend of QSslError. This means the operator is no longer a match for arguments implicitly converting to SslError, only for SslError itself. A backwards-compatible fix is to make the conversion explicit: debug << QSslError::SslError(arg). Task-number: QTBUG-125026 Change-Id: I9b6673397b6a26d508783304240c91fa058139bc Reviewed-by: Marc Mutz Reviewed-by: Ivan Solovev (cherry picked from commit f02402044e552f2940d4677039f3d02c41eb27ee) Reviewed-by: Qt Cherry-pick Bot --- src/network/compat/removed_api.cpp | 11 +++++++++++ src/network/ssl/qsslerror.cpp | 3 ++- src/network/ssl/qsslerror.h | 13 ++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/network/compat/removed_api.cpp b/src/network/compat/removed_api.cpp index ceda1175385..f24cb308bd3 100644 --- a/src/network/compat/removed_api.cpp +++ b/src/network/compat/removed_api.cpp @@ -63,6 +63,17 @@ QList QNetworkCookie::parseCookies(const QByteArray &cookieStrin #endif #include "qnetworkrequest.h" // inlined API +#include "qsslerror.h" + +#ifndef QT_NO_DEBUG_STREAM +#if QT_CONFIG(ssl) +QDebug operator<<(QDebug debug, const QSslError::SslError &error) +{ + return print(std::move(debug), error); +} +#endif +#endif + // #include "qotherheader.h" // // implement removed functions from qotherheader.h // order sections alphabetically diff --git a/src/network/ssl/qsslerror.cpp b/src/network/ssl/qsslerror.cpp index 97faa8993c9..94666fd25d7 100644 --- a/src/network/ssl/qsslerror.cpp +++ b/src/network/ssl/qsslerror.cpp @@ -348,7 +348,8 @@ QDebug operator<<(QDebug debug, const QSslError &error) debug << error.errorString(); return debug; } -QDebug operator<<(QDebug debug, const QSslError::SslError &error) + +QDebug print(QDebug debug, QSslError::SslError error) { debug << QSslError(error).errorString(); return debug; diff --git a/src/network/ssl/qsslerror.h b/src/network/ssl/qsslerror.h index d82b086d392..1f461bf26d7 100644 --- a/src/network/ssl/qsslerror.h +++ b/src/network/ssl/qsslerror.h @@ -16,6 +16,10 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_SSL +#ifndef QT_NO_DEBUG_STREAM +class QDebug; +#endif + class QSslErrorPrivate; class Q_NETWORK_EXPORT QSslError { @@ -88,16 +92,23 @@ public: private: // ### Qt 7: make QSslError implicitly shared std::unique_ptr d; +#ifndef QT_NO_DEBUG_STREAM + Q_NETWORK_EXPORT friend QDebug print(QDebug debug, QSslError::SslError error); + friend QDebug operator<<(QDebug debug, SslError error) + { return print(std::move(debug), error); } +#endif }; Q_DECLARE_SHARED(QSslError) Q_NETWORK_EXPORT size_t qHash(const QSslError &key, size_t seed = 0) noexcept; #ifndef QT_NO_DEBUG_STREAM -class QDebug; + Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError &error); +#if QT_NETWORK_REMOVED_SINCE(6, 8) Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError::SslError &error); #endif +#endif #else class Q_NETWORK_EXPORT QSslError {}; // dummy class so that moc has a complete type #endif // QT_NO_SSL