160 Commits

Author SHA1 Message Date
Marc Mutz
64ce22c61e qdebug.h: remove duplicate includes
Added by 51f702d4029148570d255daef80d071d98cf1e16 w/o rationale.

Found in API-review.

Change-Id: Ia0afd3d3aaf7a8bc392333b8359ce5b5496bec7f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit f1e1a933a610a71d93d888cc911187b80ea02e9c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-06-12 06:07:38 +00:00
Ivan Solovev
b150955043 Restore the docs for QFlags debug streaming operator
The unconstrained implementation was removed, so qdoc was not able to
find a proper function. Provide a fake definition that matches what
qdoc expects. In this case the users shouldn't really care about the
constraints that the actual implementation has.

Amends 0c707c6ebece18677deaccccdfec5d48c587106f.

Found in Qt 6.9 API review.

Pick-to: 6.9
Change-Id: I6207b491fa94cc62d217af7dc7687923dc6971a4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2025-01-22 19:33:19 +01:00
Ivan Solovev
f1d2d47f60 Fix SFINAE constraint in flags debug streaming operator
So that it allows overloading.
Also move the type T declaration into the function scope, as it
could never be used as a constraint anyway, and we do not want
users to pass custom type there.

Amends 0c707c6ebece18677deaccccdfec5d48c587106f.

Found in 6.9 API review.

Pick-to: 6.9
Change-Id: I086d65bdef7be2f9e0e67e96cc8a9ac76eaa5b0f
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2025-01-22 19:33:19 +01:00
Ivan Solovev
256b56f581 Fix docs for new QDebug streaming operators of std containers
Added the missing function declarations to the #if Q_QDOC part of the
header. Also fixed a typo in the std::unordered_map docs.

Amends 850d4895be565931d18c92e5e2f9a33b7f26de6d,
0c96528e8d43ad4309bdca14b179a5045984655a,
a9fe57fefaac0cb047e4c02e0b8c8f8327e0a58c,
and a8c9a5617c72ad2e55bf497df6ff2c2e141cbdef.

Found in Qt 6.9 API review.

Pick-to: 6.9
Change-Id: I792023b506e2afdbdca4bca3197887e50c98a788
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2025-01-17 19:29:18 +00:00
Ahmad Samir
185cba6e95 Replace qdebug.h includes in public headers with forward-declarations
qdebug.h includes many Qt and STL headers, so if you include a Qt header
you get all those transitive includes, which may affect build time.

- Where appropriate use the printf-like syntax of qDebug() and co.,
  these don't need the QDebug streaming operators
- qfloat16 is used in an inline member function, so include it
  explicitly

[ChangeLog][Potentially Source Incompatible Changes] Various Qt public
headers don't include QDebug any more; if you need QDebug's streaming
you'll have to include it in your code.

Task-number: QTBUG-132439
Pick-to: 6.9
Change-Id: I750587e17a3b38fa226cd3af8eaccc8da580f436
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2025-01-15 13:28:16 +02:00
Marc Mutz
c5a4e3f790 QDebugStateSaver: port from QScopedPointer to unique_ptr
In preparation of adding QT_NO_SCOPED_POINTER, which would be rather
pointless for users if public headers continued to mention the type.

Pick-to: 6.9 6.8
Task-number: QTBUG-132213
Change-Id: Ib5a40a1b8defe1cfe858218bb25c422f900dfe6b
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2025-01-13 00:43:30 +00:00
Thiago Macieira
4fa44a70bc qErrnoWarning: disable when QT_NO_WARNING_OUTPUT is set
Change-Id: Ife98ce915b4bd3edd017fffd18c8bb775381e6f4
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2025-01-07 18:34:27 -03:00
Thiago Macieira
8f958a6e2d QDebug: constrain the new Standard Library op<<
So they be SFINAE-ruled out when either the key or (for associative
containers) value types don't provide their debug-streaming operators
either.

Amends 850d4895be565931d18c92e5e2f9a33b7f26de6d,
0c96528e8d43ad4309bdca14b179a5045984655a,
a9fe57fefaac0cb047e4c02e0b8c8f8327e0a58c.

Fixes: QTBUG-132104
Task-number: QTBUG-130290
Pick-to: 6.9
Change-Id: I1d6703b1fdf6cfd03799fffd33191d8028ecc123
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-12-18 23:19:56 -03:00
Marc Mutz
08320bfe2b QDebug: make std::optional stream operator SCARY
Piggy-back on the recently-added, type-erased, std::tuple stream
operator to handle std::optional the same way.

While std::optional doesn't support the Tuple Protocol, and we
therefore can't use putTuple() directly, we can still use
putTupleImplImpl() if we set up its arguments manually.

[ChangeLog][Potentially Source-Incompatible Changes][QDebug] The
std::optional streaming operator is now a member of QDebug, not a free
function. This breaks users that rely on the exact definition of the
operator (e.g. `operator<<(d, opt)`). A backwards-compatible fix is to
call the operator with infix notation (d << opt) only, and to avoid
const QDebug objects.

Pick-to: 6.9
Change-Id: Ib040d65953ca9d3892aee5bdb597d6d30a9694b1
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-12-18 07:12:02 +00:00
Dheerendra Purohit
51f702d402 QDebug: add refinements to qDebug support for stl containers
Refinements of the stl containers based on the comments.

Fixes: QTBUG-131766
Change-Id: Iddca031a7b63cc24a3d4a1fdede02b8968e95be9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-12-12 16:10:43 +00:00
Dheerendra Purohit
850d4895be QDebug: add streaming operators for std::multiset
The stream insertion operator for QDebug is not overloaded
to handle std::multiset

Overload the stream insertion operator for QDebug
to handle std::multiset

[ChangeLog][QtCore][QDebug] Added support for std::multiset.

Fixes: QTBUG-131428
Change-Id: I7e3b721afe88d68c99c44c0d7cc9ee7711c169c8
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-11-26 04:25:26 +00:00
Dheerendra Purohit
0c96528e8d QDebug: add streaming operators for std::set
The stream insertion operator for QDebug is not overloaded
to handle std::set

Overload the stream insertion operator for QDebug
to handle std::set

[ChangeLog][QtCore][QDebug] Added support for std::set.

Fixes: QTBUG-130574
Change-Id: I8e1589589c8f23318bf5073609995f7da4ea1108
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-11-22 04:52:58 +00:00
Dheerendra Purohit
a8c9a5617c QDebug: add streaming operators for std::unordered_set
The stream insertion operator for QDebug is not overloaded
to handle std::unordered_set

Overload the stream insertion operator for QDebug
to handle std::unordered_set

[ChangeLog][QtCOre][QDebug] Added support for std::unordered_set.

Fixes: QTBUG-130481
Change-Id: I75a1f62f9ecb6b06ba45cc00d789cd3f3886b4c7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-11-20 22:42:38 +00:00
Dheerendra Purohit
a9fe57fefa QDebug: add streaming operators for std::unordered_map
The stream insertion operator for QDebug is not overloaded
to handle std::unordered_map

Overload the stream insertion operator for QDebug
to handle std::unordered_map

[ChangeLog][QtCore][QDebug] Added support for std::unordered_map.

Fixes: QTBUG-130290
Change-Id: I96e82f90c310dcac4a6e4d35651fb1adb6d6293a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-11-19 08:56:40 +00:00
Marc Mutz
12b41c3332 QDebug: add streaming operators for std::tuple
Unlike the existing one for std::pair, make the operator SCARY, using
the newly-added StreamTypeErased type-erasure (added in
5cdd1f594d26e1d4f84b00741be1ab7231458512).

[ChangeLog][QtCore][QDebug] Can now stream std::tuple.

Change-Id: I46670ac32eaee7f0ea5f4543ebcf59e19b394166
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-11-05 18:53:03 +00:00
Marc Mutz
25931bf218 QDebug: simplify op<<(std::optional)
We don't need to enable nospace() if we stream but a single element
(nullopt). As a consequence, delay construction of the StateSaver
until we have determined that the optional is engaged.

Amends b7657ddccbe0a5ab1cdfc61ae6b7f0501dbfb24a.

Pick-to: 6.8
Change-Id: Id974dff078cb989b92f84b63bf14956a2fba32b2
Reviewed-by: David Faure <david.faure@kdab.com>
2024-10-25 11:21:34 +02:00
Marc Mutz
c1cb30f85b QDebug: normalize std::pair output separator
All other container stream operators use COMMA SP, while std::pair
used COMMA w/o SP.

Add the space to make the output a bit more readable, and for
consistency.

[ChangeLog][QtCore][QDebug] The output of a streamed std::pair has now
a space after the separating comma, like for other containers.

Change-Id: I01f83509038566cb9369d7ec743751b2ccc0903a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-10-24 12:10:02 +02:00
Thiago Macieira
094f7cab54 QDebug: improve support for printing 64-bit QFlags
Like the 32-bit version, we add an explicitly-exported non-template
overload. And we can call the 64-bit implementation from the 32-bit one
to save in code generation inside QtCore.

Task-number: QTBUG-111926
Change-Id: I8a96935cf6c742259c9dfffd17e9928218333c04
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-10-09 15:48:15 -07:00
Thiago Macieira
2effeb25c0 Long live 64-bit QFlags
This commit removes the limitation on size that QFlags used to have,
allowing up to 64 bits. We could increase to 128 bits at this time, but
I'm choosing not to allow this yet, due to limitations in handling
128-bit integers in QMetaObject & QMetaObjectBuilder. The API wouldn't
be cross-platform.

This commit duplicates the tst_QFlags into a new tst_QFlags64. It
restores the tst_QVariant state to how it was before (even though it
doesn't actually test the QMetaEnum functionality).

[ChangeLog][QtCore][QFlags] Now supports 64-bit enumerations, with the
same syntax, including extraction into QMetaObject using the Q_FLAG and
Q_DECLARE_FLAGS markers. Note the QFlag helper class remains 32-bit
wide. Creation of a 64-bit QFlags from a generic integer can be achieved
by passing a std::in_place first argument.

Fixes: QTBUG-111926
Change-Id: Ifb754f0e28774c20aa7cfffd17e7fc1d16baf8e4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2024-10-04 10:44:57 -07:00
Thiago Macieira
0c707c6ebe QFlags: simplify operator<< for QDebug
Instead of declaring three different template overloads (with an #if in
the middle), reduce to explicitly two:
 1) one for the Q_ENUMs that aren't QFlags
 2) one for QFlags

This does change how an enum that is a Q_FLAG gets printed: previously,
it was printed as itself, now it's printed as QFlags, even if no QFlags
are present.

Then use if constexpr for that second one to get the enumeration from
QMetaObject, if the flags are associated with a QMetaObject.

Change-Id: Ifb754f0e28774c20aa7cfffd17e7f8b9c68b292b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-08-14 12:28:48 -07:00
Thiago Macieira
232ad339ab QDebug: cast the QFlags value to the right-sized unsigned type (2/2)
This applies to the Q_ENUM/Q_FLAGS overload of the debugging functions.
This prevents the sign-extension of a signed QFlags field when
converting to quint64, which would have resulted in 0x8000'0000 becoming
0xffff'ffff'8000'0000.

Right now, this is a no-op change because the implementation in
qt_QMetaEnum_flagDebugOperator() calls QMetaEnum::valueToKey(), which is
limited to int (32 bits).

Pick-to: 6.8
Change-Id: I8a96935cf6c742259c9dfffd17e998c3a0538146
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-08-10 11:06:45 -07:00
Thiago Macieira
91a27c1a51 QDebug: cast the QFlags value to the right-sized unsigned type (1/2)
This change fixes three problems in the non-Q_ENUM overload. First, the
printing of the sign bit for a signed flag. This is correct, but
unexpected:
  QFlags(0x1|0x2|-0x80000000)
By using unsigned types, we'll print instead:
  QFlags(0x1|0x2|0x80000000)

Second, shifting into the sign bit is UB, so we remove the problem by
not having a sign bit at all.

Third, this provides an out-of-line non-template overload of the
implementation for unsigned QFlags, thereby avoiding an unnecessary
instantiation of the template function qt_QMetaEnum_flagDebugOperator()
in user code.

Pick-to: 6.8
Change-Id: I8a96935cf6c742259c9dfffd17e992caa315e1d3
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-08-10 11:06:45 -07:00
Tatiana Borisova
2aa39be4c2 Add QDebug printing for the std/Qt::<name>_ordering types
[ChangeLog][QtCore][QDebug] Added possibility to print {std/Qt}
weak/partial/strong_ordering values with QDebug << operator.

Change-Id: Ie880cb34c19f79a404c692c2322b3460d72bfde4
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-08-01 11:04:23 +00:00
Jøger Hansegård
a0bd57059d Call std::addressof instead of operator& in QDebug::toBytes
QDebug::toBytes intends to pass the input object's address to its
nested implementation, but was calling operator& which does not work
with types that has a custom overload. Calling std::addressof fixes this
problem.

Task-number: QTBUG-127510
Change-Id: I63a682d7053ded7b9ee5eef2fa2da02cf0e76cce
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-07-25 11:19:07 +02:00
Jøger Hansegård
6cd6c3d6d7 Call std::addressof instead of operator& in QDebug::toString
QDebug::toString intends to pass the input object's address to its
nested implementation, but was calling operator& which does not work
with types that has a custom overload. Calling std::addressof fixes this
problem.

Fixes: QTBUG-127510
Pick-to: 6.8
Change-Id: Ie608f7b1a63c4032246b6ff98a3651695f0536ca
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-07-25 11:19:04 +02:00
Marc Mutz
b57fac818b Long live QDebug::toBytes()!
I've seen over and over again how test authors are plagued by the
impedance mismatch between their 8-bit actual data and the result of
QString::toString() being in UTF-16. They invariably ditch their 8-bit
inputs and go to QString, but the mere fact that they start out with
8-bit input and then run into problems means we have a gaping API hole
here. QTest::toString() also suffers from this.

So add the option to a) construct a QDebug object over a QByteArray
(already supported by underlying QTextStream) and b) to stream into
QByteArray like toString() streams into QString.

Finally, make QTest::toString() use the new toBytes() function instead
of the old toString() one.

This saves 1% (91122→90248) in tst_tostring exeutable size on
optimized Linux AMD64 GCC 9 builds.

[ChangeLog][QtCore][QDebug] Added ctor from QByteArray* and a static
toBytes() function.

Change-Id: I2b021513d6427a1a961f39e751eaf4faaf527ba8
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-07-23 02:59:53 +02:00
Marc Mutz
5cdd1f594d QDebug: make toString() SCARY
Extract the non-template-dependent code into an out-of-line function
and pass the actual streaming operation as a callback.

Saves 4% (174811→167936) in executable size for tst_qdebug and 2.7%
(93639→91122) for tst_tostring on Linux GCC 9 AMD64 release builds.

Pick-to: 6.8
Change-Id: If232e5b26c66981ffcb614f1bdb7007c71e879bf
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-07-21 22:22:28 +02:00
Marc Mutz
a9ab406a69 QDebug: make Stream ctors explicit
Their argument types are not faithful representations of a Stream
object, so ctors should not be implicit. Besides, the QDebug ctors
that delegate to these Stream ctors are explicit, too, with the same
arguments.

Pick-to: 6.8
Change-Id: I8048e26e890009cc8f6bc3ce49e2c01af1e89514
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-07-21 00:57:37 +00:00
Marc Mutz
13244eef6c Fix signature of QDebug::toString() (again)
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.

Pick-to: 6.8
Change-Id: Iac1ee9d29f93fd4840b75ffe363d354a2d19a96e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-07-20 22:56:49 +02:00
Aurélien Brooke
b294927a12 QDebug: add support for std::array
[ChangeLog][QtCore][QDebug] Can now output std::array

Change-Id: I1f03ddd2e5995ba550d73e785d7449603a0db302
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-07-14 17:55:21 +02:00
Marc Mutz
b2eb422699 qtypeinfo.h: move QTypeTraits part to qttypetraits.h
Makes sense to collect the stuff in a similarly-named header, and it's
not like any of the QTypeTraits stuff was needed for QTypeInfo.

Makes #include <qtypeinfo.h> _much_ lighter again, at the expense of
qminmax.h now getting <variant>, <tuple> and <optional> instead, but
qminmax.h is much easier to avoid in Qt headers (just use the std
versions) than qtypeinfo.h.

[ChangeLog][QtCore][Potentially Source-Incompatible Changes] The
qtypeinfo.h header no longer transitively includes <optional>, <tuple>
and <variant>.

Task-number: QTBUG-97601
Pick-to: 6.8
Change-Id: Ied96113f38c1232fef3ec79847ee62f06c68f268
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-06-04 11:31:56 +00:00
Marc Mutz
7e8196510d QDebug: fix copy-instead-of-move issues
Coverity correctly complains that we're copying the QDebug object when
calling print*Container() when we could have moved it into the helper.

So do move it.

Pick-to: 6.7 6.6 6.5
Coverity-Id: 406803
Coverity-Id: 407406
Coverity-Id: 408523
Coverity-Id: 408562
Coverity-Id: 418431
Coverity-Id: 424788
Coverity-Id: 425106
Coverity-Id: 426537
Coverity-Id: 427163
Coverity-Id: 428925
Coverity-Id: 444463
Change-Id: Ic80247f315a09fffe9363577dff1d1c781859304
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2024-03-25 16:22:05 +01:00
Marc Mutz
620eb390c0 QDebug: add missing #include <optional>
Found in API review.

Amends b7657ddccbe0a5ab1cdfc61ae6b7f0501dbfb24a.

Pick-to: 6.7
Change-Id: Ibdab7f51be09036659475bd76af28e8692235b9c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-01-15 13:28:31 +00:00
Marc Mutz
ab910e09c7 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>
2023-12-09 21:00:13 +01:00
Marc Mutz
9d54b5c57e QDebug: remove QPair streaming docs
QPair _is_ std::pair. If this wasn't a fake-definition under #ifdef
Q_QDOC, the compiler would have complained long ago.

Pick-to: 6.6 6.5
Change-Id: Idfe589ff13115d3d908572a17b849f634ec86787
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-07 23:55:07 +01:00
David Faure
b7657ddccb qDebug: add support for std::optional and std::nullopt_t
[ChangeLog][QtCore][QDebug] Added support for std::optional
and std::nullopt_t

Change-Id: I1e6196adb408401cae8776cd0c60af294a39a83f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-11-22 05:56:25 +01:00
Marc Mutz
568ab62185 QDebug: rewrite timeUnit() into putTimeUnit()
This avoids us committing to the QByteArray return value, which is
overkill for short strings. Instead, pull the streaming of the unit
behind the ABI boundary, so we're free to change the implementation to
either stream directly or use SSO'ed std::string.

Pick-to: 6.6
Change-Id: I10927acb9d64077d9018b667958ca16be218012a
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-07-10 13:51:52 +00:00
Marc Mutz
af32768f18 QDebug: add getter/setter for noQuotes
There were setters (quote(), noquote()), but, unlike
space()/nospace(), there was no getter.

Add the getter, and, for symmetry, a parametrized setter, too.

[ChangeLog][QtCore][QDebug] Added setQuoteStrings()/quoteStrings() to
access and manipulate the quote()/noquote() state.

Change-Id: I1b73138819b4d02726a6ef862c190206431ccebc
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-07-05 12:56:55 +02:00
Marc Mutz
8cad4c2903 QDebugStateSaver: mark ctors [[nodiscard]]
It's a RAII class, and RAII classes should have only [[nodiscard]]
constructors.

Pick-to: 6.6
Task-number: QTBUG-104164
Change-Id: Ia83fa003677a839734208b12bde2c6287c1b79a3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-06-20 13:25:05 +00:00
Marc Mutz
ba501285b5 QDebugStateSaver: unexport
We should not export non-polymorophic classes wholesale. Only export
the non-inline functions instead.

There are no implicitly-declared special member functions in this
class that could cause problems, so we don't need to delay until Qt 7.

Pick-to: 6.6
Change-Id: I204d703498bf42465ea122d1f31c443ea439bd6e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-06-14 10:00:58 +02:00
Thiago Macieira
a2551c45d4 Move the formatting of <chrono> durations to QDebug & QtTest
[ChangeLog][QtCore][QDebug] Added pretty formatting of C++ <chrono>
durations.

[ChangeLog][QtTest] Added pretty formatting of C++ <chrono> durations
for QCOMPARE expressions.

Change-Id: I3b169860d8bd41e9be6bfffd1757cc087ba957fa
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-05-06 17:54:23 +00:00
Edward Welbourne
db5279825c Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definition
I got tired of being told off by the inanity 'bot for faithfully
reflecting existing #if-ery in new #if-ery. Retain only the
documentation and definition of the deprecated define.

Change-Id: I47f47b76bd239a360f27ae5afe593dfad8746538
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2023-03-20 19:18:52 +01:00
Ahmad Samir
f325bdacb6 Replace ushort*/uint* with char16_t*/char32_t* in private API [1]
Task-number: QTBUG-110403
Pick-to: 6.5
Change-Id: Ie20a831f22212d56659cf3c6940d17134ab5f2c5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-15 20:25:57 +00:00
Marc Mutz
52c7f699ac QDebug: fix std::string/view stream operators; add u8 versions
Make them templates, for two reasons:

- so they can accept std::pmr types and, in general, any basic_string
  with custom allocators and char_traits

- to break overload ambiguities with the Qt string view types

Also, add the missing C++20 char8_t overloads.

Also, avoid creation of a QString in the sizeof(wchar_t) == 2 case
(Windows). Add a comment to optimize for the sizeof(wchar_t) != 2 case
later.

Found in API review.

Pick-to: 6.5
Change-Id: I30139520f582a38863a0936f8eca4b1ed33e37c8
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-03-02 06:33:35 +01:00
Thiago Macieira
5838074912 qfloat16: add QTextStream & QDebug streaming operators
Change-Id: Ieba79baf5ac34264a988fffd172655bdcaf12a59
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2022-11-28 10:59:34 -08:00
Luca Di Sera
e2fef733be Replace usages of Q_CLANG_QDOC with Q_QDOC
To allow the user to customize the C++ code that QDoc sees, so as to be
able to work-around some limitations on QDoc itself, QDoc defines two
symbols: Q_QDOC and Q_CLANG_QDOC, both of which are "true" during an
entire execution of QDoc.

At a certain point in time, QDoc allowed the user the choice between a
custom C++ parser and a Clang based one.

The Q_QDOC symbol would always be defined while the Q_CLANG_QDOC symbol
would be defined only when the Clang based parser was chosen.

In more recent times, QDoc always uses a Clang based parser, such that
both Q_CLANG_QDOC and Q_QDOC are always defined, making them equivalent.

To avoid using different symbols, and the possible confusion and
fragmentation that derives from it, all usages of Q_CLANG_QDOC are now
replaced by the equivalent usages of Q_QDOC.

Change-Id: I5810abb9ad1016a4c5bbea99acd03381b8514b3f
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
2022-10-21 09:48:36 +02:00
Marc Mutz
df9d882d41 Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:

  auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
  makeRule(cxxMemberCallExpr(on(QtContainerClass),
                             callee(cxxMethodDecl(hasAnyName({"count", "length"),
                                                  parameterCountIs(0))))),
           changeTo(cat(access(o, cat("size"), "()"))),
           cat("use 'size()' instead of 'count()/length()'"))

a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.

<classes> are:

    // sequential:
    "QByteArray",
    "QList",
    "QQueue",
    "QStack",
    "QString",
    "QVarLengthArray",
    "QVector",
    // associative:
    "QHash",
    "QMultiHash",
    "QMap",
    "QMultiMap",
    "QSet",
    // Qt has no QMultiSet

Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-10-04 07:40:08 +02:00
Fabian Kosmale
a0dfa8c4d2 Replace qExchange calls with std::exchange
qExchange is one of the few remaining functionalities that have not been
moved out of qglobal. Given that std::exchange exists in the standard, we
can simply move to it everywhere...

...if it weren't for the fact that std::exchange is only constexpr in
C++20, and only has its noexceptness specified in (most likely) C++23.
Still, we want to move to the existing std functionality where
possible, to allow the removal of qglobal includes in lieu of something
more fine-grained in the future.
So leave any constexpr calls[1] alone for now (and observe that none of
our current usages cares about the conditional noexceptness), but
replace everything else.

[1] QScopedValueRollback' ctor and QExplicitlySharedDataPointerV2::take

Task-number: QTBUG-99313
Change-Id: I599cb9846cf319c7ffd3457130938347a75aad25
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-09-28 17:39:21 +00:00
Ville Voutilainen
e08f05ac6e QDebug: Support standard strings and string views directly
[ChangeLog][QtCore][QDebug] QDebug now supports printing
std::strings and std::string_views (and their wide, u16, and
u32 variants) directly.

Task-number: QTBUG-96878
Change-Id: I7baf4fe688bfff50580b1cee9417af13949374cc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-09-27 14:12:11 +03:00
Marc Mutz
d8561b1dea QDebug: finish porting to qsizetype/size_t
Port two variables from int/uint to qsizetype/size_t. These don't
cause problems, because their possible ranges are limited, however,
int/uint variables are a code smell these days, so replace them
nonetheless.

[ChangeLog][QtCore][QDebug] Fixed issues on 64-bit platforms when
streaming containers (incl. strings) of more than 2Gi elements.

Pick-to: 6.4 6.3 6.2
Task-number: QTBUG-103525
Change-Id: Ica6c5a6a062990306280fb713c47adb2053b752d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-21 08:29:11 +02:00