From 67385c04ce272cf553bc2e8aa8e923cd7851fc66 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 9 Feb 2022 10:45:48 +0100 Subject: [PATCH] QDataStream: make qfloat16 streaming a non-member Remove the member function from the API and re-add it as a hidden friend on qfloat16, where it will be a complete type. [ChangeLog][QtCore][Potentially Souce-Incompatible Changes] The qfloat16 QDataStream operators are now hidden friends and only found by argument-dependent lookup. Previously, these were member functions on QDataStream. Fixes: QTBUG-93499 Pick-to: 6.3 Change-Id: Ib3d4df7a3fe3a9d0938f3be8b70b50fef0416262 Reviewed-by: Qt CI Bot Reviewed-by: Lars Knoll --- src/corelib/compat/removed_api.cpp | 17 +++++++++++ src/corelib/global/qfloat16.cpp | 37 +++++++++++++++++++++++ src/corelib/global/qfloat16.h | 9 ++++++ src/corelib/serialization/qdatastream.cpp | 27 ----------------- src/corelib/serialization/qdatastream.h | 8 +++-- 5 files changed, 69 insertions(+), 29 deletions(-) diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index 16811bf37e6..b856f6b495b 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -103,6 +103,23 @@ QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method) return hash(QByteArrayView{data}, method); } +#include "qdatastream.h" + +# ifndef QT_NO_DATASTREAM +# include "qfloat16.h" + +QDataStream &QDataStream::operator>>(qfloat16 &f) +{ + return *this >> reinterpret_cast(f); +} + +QDataStream &QDataStream::operator<<(qfloat16 f) +{ + return *this << reinterpret_cast(f); +} + +# endif + #include "quuid.h" QUuid::QUuid(const QString &text) diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp index 0eb6ec10100..62c87234a2b 100644 --- a/src/corelib/global/qfloat16.cpp +++ b/src/corelib/global/qfloat16.cpp @@ -42,6 +42,8 @@ #include "private/qsimd_p.h" #include // for fpclassify()'s return values +#include + QT_BEGIN_NAMESPACE QT_IMPL_METATYPE_EXTERN(qfloat16) @@ -394,6 +396,41 @@ Q_CORE_EXPORT void qFloatFromFloat16(float *out, const qfloat16 *in, qsizetype l out[i] = float(in[i]); } +#ifndef QT_NO_DATASTREAM +/*! + \fn qfloat16::operator<<(QDataStream &ds, qfloat16 f) + \relates QDataStream + \since 5.9 + + Writes a floating point number, \a f, to the stream \a ds using + the standard IEEE 754 format. Returns a reference to the stream. + + \note In Qt versions prior to 6.3, this was a member function on + QDataStream. +*/ +QDataStream &operator<<(QDataStream &ds, qfloat16 f) +{ + return ds << f.b16; +} + +/*! + \fn qfloat16::operator>>(QDataStream &ds, qfloat16 &f) + \relates QDataStream + \since 5.9 + + Reads a floating point number from the stream \a ds into \a f, + using the standard IEEE 754 format. Returns a reference to the + stream. + + \note In Qt versions prior to 6.3, this was a member function on + QDataStream. +*/ +QDataStream &operator>>(QDataStream &ds, qfloat16 &f) +{ + return ds >> f.b16; +} +#endif + QT_END_NAMESPACE #include "qfloat16tables.cpp" diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 8361dd8764f..d9fd89215d3 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -67,6 +67,10 @@ QT_BEGIN_NAMESPACE #pragma qt_no_master_include #endif +#ifndef QT_NO_DATASTREAM +class QDataStream; +#endif + class qfloat16 { struct Wrap @@ -200,6 +204,11 @@ QT_WARNING_DISABLE_FLOAT_COMPARE #undef QF16_MAKE_BOOL_OP_INT QT_WARNING_POP + +#ifndef QT_NO_DATASTREAM + friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds, qfloat16 f); + friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &ds, qfloat16 &f); +#endif }; Q_DECLARE_TYPEINFO(qfloat16, Q_PRIMITIVE_TYPE); diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index 67423ee62c4..69b497d0e57 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -991,20 +991,6 @@ QDataStream &QDataStream::operator>>(double &f) } -/*! - \overload - \since 5.9 - - Reads a floating point number from the stream into \a f, - using the standard IEEE 754 format. Returns a reference to the - stream. -*/ -QDataStream &QDataStream::operator>>(qfloat16 &f) -{ - return *this >> reinterpret_cast(f); -} - - /*! \overload @@ -1340,19 +1326,6 @@ QDataStream &QDataStream::operator<<(double f) } -/*! - \fn QDataStream &QDataStream::operator<<(qfloat16 f) - \overload - \since 5.9 - - Writes a floating point number, \a f, to the stream using - the standard IEEE 754 format. Returns a reference to the stream. -*/ -QDataStream &QDataStream::operator<<(qfloat16 f) -{ - return *this << reinterpret_cast(f); -} - /*! \overload diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index 584de3166a7..ac0adc1bf9f 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -51,7 +51,9 @@ QT_BEGIN_NAMESPACE +#if QT_CORE_REMOVED_SINCE(6, 3) class qfloat16; +#endif class QByteArray; class QIODevice; @@ -160,8 +162,9 @@ public: QDataStream &operator>>(std::nullptr_t &ptr) { ptr = nullptr; return *this; } QDataStream &operator>>(bool &i); - // ### Qt 7: remove the operator or make qfloat16 fully defined, see QTBUG-93499 +#if QT_CORE_REMOVED_SINCE(6, 3) QDataStream &operator>>(qfloat16 &f); +#endif QDataStream &operator>>(float &f); QDataStream &operator>>(double &f); QDataStream &operator>>(char *&str); @@ -179,8 +182,9 @@ public: QDataStream &operator<<(quint64 i); QDataStream &operator<<(std::nullptr_t) { return *this; } QDataStream &operator<<(bool i); - // ### Qt 7: remove the operator or make qfloat16 fully defined, see QTBUG-93499 +#if QT_CORE_REMOVED_SINCE(6, 3) QDataStream &operator<<(qfloat16 f); +#endif QDataStream &operator<<(float f); QDataStream &operator<<(double f); QDataStream &operator<<(const char *str);