diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2023-09-14 18:22:12 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2023-12-09 21:00:13 +0100 |
| commit | ab910e09c713161f568a867a09af5a52eb79c35f (patch) | |
| tree | 0c03a2cab401ad7d806389edc51d19769461df86 /src/corelib/io/qdebug.h | |
| parent | f9f1272e7c438b79591032877f2b386af8085c3f (diff) | |
Long live QDebug::operator<<(q(u)int128)!
Replace the ad-hoc implementation of QTest::toString() in
tst_qglobal.cpp with a QDebug stream operator, so the
QTest::toString() fall-back to QDebug::toString() kicks in.
Since the ABI issues revolving around the new int128 types are not
known, yet, avoid baking the types into the ABI by a) making the
operators constrained templates¹ and b) passing though void* to the
exported helpers. These functions return an error message if Qt was
compiled without support for int128.
Use the Thiago Trick™ (leaving obviouly dead code around for the
compiler to remove without warning) to expose more code to more
compilers. This appears to work elsewhere in Qt, so I hope it does
here, too.
This completes the minimum qint128 support so we're able to debug code
and write tests that use these types.
¹ Templates, unlike inline member functions of wholly-exported
classes, never² become part of the ABI.
² <insert here the convoluted scenario under which this is false>
Fixes: QTBUG-117011
Change-Id: Ia4e56d26c6ffd18b7d69a7ceaed65b2211d258b2
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/io/qdebug.h')
| -rw-r--r-- | src/corelib/io/qdebug.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 95663142339..c7ab4c25538 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -11,6 +11,7 @@ #include <QtCore/qcontainerfwd.h> #include <QtCore/qtextstream.h> +#include <QtCore/qtypes.h> #include <QtCore/qstring.h> #include <QtCore/qcontiguouscache.h> #include <QtCore/qsharedpointer.h> @@ -69,6 +70,8 @@ class QT6_ONLY(Q_CORE_EXPORT) QDebug : public QIODeviceBase QT7_ONLY(Q_CORE_EXPORT) void putString(const QChar *begin, size_t length); QT7_ONLY(Q_CORE_EXPORT) void putByteArray(const char *begin, size_t length, Latin1Content content); QT7_ONLY(Q_CORE_EXPORT) void putTimeUnit(qint64 num, qint64 den); + QT7_ONLY(Q_CORE_EXPORT) void putInt128(const void *i); + QT7_ONLY(Q_CORE_EXPORT) void putUInt128(const void *i); public: explicit QDebug(QIODevice *device) : stream(new Stream(device)) {} explicit QDebug(QString *string) : stream(new Stream(string)) {} @@ -203,6 +206,21 @@ public: return maybeSpace(); } +#ifdef QT_SUPPORTS_INT128 +private: + // Constrained templates so they only match q(u)int128 without conversions. + // Also keeps these operators out of the ABI. + template <typename T> + using if_qint128 = std::enable_if_t<std::is_same_v<T, qint128>, bool>; + template <typename T> + using if_quint128 = std::enable_if_t<std::is_same_v<T, quint128>, bool>; +public: + template <typename T, if_qint128<T> = true> + QDebug &operator<<(T i128) { putInt128(&i128); return maybeSpace(); } + template <typename T, if_quint128<T> = true> + QDebug &operator<<(T u128) { putUInt128(&u128); return maybeSpace(); } +#endif // QT_SUPPORTS_INT128 + template <typename T> static QString toString(T &&object) { |
