137 Commits

Author SHA1 Message Date
Marc Mutz
e5e560c7fd 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.

Change-Id: Id974dff078cb989b92f84b63bf14956a2fba32b2
Reviewed-by: David Faure <david.faure@kdab.com>
(cherry picked from commit 25931bf2181706e1cba416b0530f07959182f074)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-10-26 00:04:46 +00:00
Thiago Macieira
3d90aa1771 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).

Change-Id: I8a96935cf6c742259c9dfffd17e998c3a0538146
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 232ad339ab14965b6207d04a45d8d37ec3139558)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-08-12 09:43:38 +00:00
Thiago Macieira
9883f88850 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.

Change-Id: I8a96935cf6c742259c9dfffd17e992caa315e1d3
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 91a27c1a516068b69ab62778a07c566ad22f3576)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-08-12 09:43:38 +00:00
Jøger Hansegård
b64e918c85 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
Change-Id: Ie608f7b1a63c4032246b6ff98a3651695f0536ca
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 6cd6c3d6d70f8e76059153dd58ed2c61af2889b3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-07-25 11:21:35 +00:00
Marc Mutz
853f7b661f 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.

Change-Id: If232e5b26c66981ffcb614f1bdb7007c71e879bf
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 5cdd1f594d26e1d4f84b00741be1ab7231458512)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-07-21 23:06:54 +00:00
Marc Mutz
c8771a3082 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.

Change-Id: I8048e26e890009cc8f6bc3ce49e2c01af1e89514
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit a9ab406a69f4edc4228cc2effbcde309fcdcf411)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-07-21 15:01:31 +00:00
Marc Mutz
ae515c3f2e 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.

Change-Id: Iac1ee9d29f93fd4840b75ffe363d354a2d19a96e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 13244eef6c913bb7f27cd8fbf459f5dfe9a0ed21)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-07-21 15:01:31 +00:00
Marc Mutz
aec1edfe40 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
Change-Id: Ied96113f38c1232fef3ec79847ee62f06c68f268
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit b2eb422699118f4ae8370519b4c7bb3fe121beb2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-04 13:42:16 +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
Marc Mutz
db44800627 QContiguousCache: fix streaming into QDebug when indices are > INT_MAX
As usual, int/qsizetype mismatch.

Pick-to: 6.4 6.3 6.2
Task-number: QTBUG-103525
Change-Id: Ic5d9fb4fd42e4534ec0358ca7c4d79650c6ac919
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-21 08:29:04 +02:00
Marc Mutz
bc2b8411c9 QDebug: finish porting put{String,ByteArray} to qsizetype
The underlying QTextStream seems to support qsizetype-sized data and
the private API of QDebug that is under consideration in this patch
takes size_t, but, as so often, there're int/uint casts in-between
that break things.

Widen the int/uint casts to qsizetype/size_t, respectively.

Pick-to: 6.4 6.3 6.2
Task-number: QTBUG-103525
Change-Id: I10bca093dc2d6f136871c94ca43f5b42fd1c8971
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-21 08:28:59 +02:00
Marc Mutz
16c453069f QtBase: eradicate QT_STRINGVIEW_LEVEL uses
It's not used and not useful.

The macro itself has to stay, for now, because Qt5Compat uses it, too.

Task-number: QTBUG-100861
Pick-to: 6.4 6.3 6.2
Change-Id: I5d0557a6c959d6facf6e47f26786a9d365339e95
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2022-07-20 13:15:55 +02:00
Marc Mutz
c84897c137 QDebug: add op<< for std::initializer_list
We need it in QtHttpServer.

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

Change-Id: I3e940215fb4f4778bd782ea9b30960754ac23d47
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2022-07-06 17:56:58 +02:00
Alexey Edelev
36ea34c714 Add the qt_class pragma to file listed in sync.profile classnames map
This makes header files self-contained and reduces the number of
'sources of truth' for syncqt procedure.

Change-Id: I7f5865abc69934603139d23e1b5452da46ccb110
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-06-22 03:03:31 +02:00
Lucie Gérard
05fc3aef53 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-05-16 16:37:38 +02:00
Tor Arne Vestbø
aa0a53fc19 Don't declare type 'id' in the global namespace in a public header
It's not necessary, and it breaks the qttools build (where we have a
global variable named 'id'), and thus will most certainly build a lot
of existing user code.

Amends e47c22480fe84c100019cd92d0296f0dd2a7f3f1.

Change-Id: I97a91c2cb23fdae65143cf14c81570cf88d529d5
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-04-27 00:16:26 +02:00
Tor Arne Vestbø
e47c22480f Add QDebug operator for Objective-C id type
Not every id is an NSObject, and even those that are are sometimes
passed around as id<SomeProtocol>, in which case we still want them
to have pretty debug descriptions.

Change-Id: I50a02cd8fb9d6a2cbde3c4aef81116033d10b72c
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-04-21 10:24:31 +02:00
Sona Kurazyan
b625195893 QtCore: Replace remaining uses of QLatin1String with QLatin1StringView
Task-number: QTBUG-98434
Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2022-03-26 01:44:05 +01:00
Fabian Kosmale
fb0c7a9956 QVariant: reduce transitive includes
Forward declare more types in qvariant.h, and do the same for qdebug.h
(which will be removed from qvariant in a separate patch).

As we now only forward declare containers (e.g. QMap, QList, ...), code
which includes <QVariantMap>, <QVariantList>... breaks without further
adjustment: So far, those headers simply included qvariant.h. However,
by introducing new actual headers for those types and adjusting
sync.profile, we can avoid this issue.

To avoid breaking leaf modules and user code, we make the change opt-in:
Unless QT_LEAN_HEADERS is defined to a value of >= 1, we still
include the superfluous headers. We also set this macro in qtbase via
QT_EXTRA_INTERNAL_TARGET_DEFINES.

[ChangeLog][Potentially Source-Incompatible Changes] qvariant.h no
longer includes <QList>, <QMap>, <QHash>, <QVarLengthArray>, <QSet> and
<QObject>. Code that relied on transitive includes might need to
explicitly include those headers now. Notably, including <QVariant> (or
qvariant.h) is no longer sufficient when using QVariant(List|Map|Hash).
Using them now requires including respectively <QVariantList>,
<QVariantMap>, or <QVariantHash>. Alternatively, including <QVariant>
and the <QList>, <QMap> or <QHash> header also works.

[ChangeLog][Potentially Source-Incompatible Changes] qdebug.h no longer
includes <QSet>, <QHash>, <QVarLengthArray> and <QMap>. Code that relied
on transitive includes might need to explicitly include those headers
now.

Task-number: QTBUG-97601
Change-Id: I142e5de709ed0b305716369a3266389ab7fbbb71
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2022-03-17 16:14:38 +00:00
Thiago Macieira
4ccd974ada QDebug: unexport most of the class for Qt 7
Only a few helper methods need to be exported.

Change-Id: I74249c52dc02478ba93cfffd16d2e8eac8a13182
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2022-02-17 22:20:07 -08:00
Marc Mutz
b1b0c2970e QtCore: replace qSwap with std::swap/member-swap where possible
qSwap() is a monster that looks for ADL overloads of swap() and also
detects the noexcept of the wrapped swap() function, so it should only
be used when the argument type is unknown. In the vast majority of
cases, the type is known to be efficiently std::swap()able or to have
a member-swap. Call either of these.

For the common case of pointer types, circumvent the expensive trait
checks on std::swap() by providing a hand-rolled qt_ptr_swap()
template, the advantage being that it can be unconditionally noexcept,
removing all type traits instantiations. Don't document it, otherwise
we'd be unable to pick it to 6.2.

Effects on Clang -ftime-trace of a PCH'ed libQt6Gui.so build:

before:

  **** Template sets that took longest to instantiate:
   [...]
   27766 ms: qSwap<$> (9073 times, avg 3 ms)
   [...]
    2806 ms: std::swap<$> (1229 times, avg 2 ms)

   (30572ms)

after:

  **** Template sets that took longest to instantiate:
   [...]
   5047 ms: qSwap<$> (641 times, avg 7 ms)
   [...]
   3371 ms: std::swap<$> (1376 times, avg 2 ms)
   [qt_ptr_swap<$> does not appear in the top 400, so < 905ms]

   (< 9323ms)

As a drive-by, remove superfluous inline keywords and template
ornaments.

Task-number: QTBUG-97601
Pick-to: 6.3 6.2
Change-Id: I88f9b4e3cbece268c4a1238b6d50e5712a1bab5a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2022-01-20 22:56:12 +01:00
Joerg Bornemann
51cc8a7267 Fix QDebug operator<< for QMultiMap when Q_CLANG_QDOC is defined
This amends commit 8a8bf1b84e9a096993b892873eb62c735149f320.

Pick-to: 6.2
Change-Id: If863d33d055e0a743606d11859b11c112de105f1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-10-27 15:00:31 +02:00
Sona Kurazyan
8a8bf1b84e Fix docs for comparison/debug/data stream operators of Qt containers
Because of the constraints on comparison, debug and data stream
operators, the return types for them look weird in docs. Conditionally
use the actual return types, in case if Q_CLANG_QDOC is defined.

Also add the docs of debug stream operators for types for which they
were misssing.

Task-number: QTBUG-97247
Pick-to: 6.2
Change-Id: I57f2c52bd3af805c7eeebb602c47de1e95ee09bd
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2021-10-18 13:42:07 +02:00
Sona Kurazyan
9f13842fe6 Fix compilation for recursive Qt containers
The operator checks cause compilation errors when trying to check for
their existence for recursive containers. This happens because of trying
to check for the operators on the template parameter type(s), that
inherit from the container itself, which leads to compilation errors.
Introduced alternative versions of the operator checks (with _container
suffix), that first check if the container is recursive, i.e. any of its
template parameter types inherits from the given container, and skips
the operator check, if that's the case.

The fix is done for all Qt container types that had the problem, except
for QVarLengthArray and QContiguousCache, which don't compile with
recursive parameter types for unrelated reasons.

Fixes: QTBUG-91707
Pick-to: 6.2 6.1
Change-Id: Ia1e7240b4ce240c1c44f00ca680717d182df7550
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-09-07 15:48:35 +02:00
Marc Mutz
734429f4a3 QDebug: add support for QVarLengthArray
Remove a conflicting definition of the same operator from
qrhi.cpp. Who knows how many ODR violations this hidden gem may have
caused...

[ChangeLog][QtCore][QDebug] Can now stream QVarLengthArray objects.

[ChangeLog][QtCore][QVarLengthArray] Can now be output via QDebug
streaming.

Change-Id: I12f7670e32029fa8c96b446e9a98ebf3b9732d0d
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2021-06-13 21:01:24 +02:00
Giuseppe D'Angelo
6e04664a95 QDebug: code tidies
Use the newly introduced QFlags::toInt().

Change-Id: I45337a299d20738767461c36641519a3e9b625d7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-05-12 23:04:57 +02:00
Allan Sandfeld Jensen
bf820bd3e2 Fix c++20 builds
Change-Id: I5c44fd72fea9bf1a5aafefa2dfd935295a519819
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2020-11-14 09:28:37 +01:00
Karsten Heimrich
e9b92c926d QDebug: add op<<(QUtf8StringView)
[ChangeLog][QtCore][QDebug] Added streaming of QUtf8StringViews.

Task-number: QTBUG-88029
Change-Id: Ifcb001cfebddd79ce1cdbfef5bcc19f7c56679ec
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2020-11-07 09:35:11 +01:00
Karsten Heimrich
7cad91a7df QDebug: add op<<(QByteArrayView)
[ChangeLog][QtCore][QDebug] Added streaming of QByteArrayViews.

Task-number: QTBUG-88029
Change-Id: I66f5cc45a0438dbaacb1754cb3c669b3717f528b
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2020-11-07 09:35:11 +01:00
Lars Knoll
4097653215 Fix signature of QDebug::toString()
We don't need two overloads here.

Change-Id: Ia6a3bcd93491843e07b0295fefe8da42ae9d6519
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2020-10-16 09:48:09 +02:00
Giuseppe D'Angelo
889d40ebe2 Centralize the implementation of move assignment operators
At the moment we have two main strategies for dealing with move
assignment in Qt:

1) move-and-swap, used by "containers" (in the broad sense): containers,
but also smart pointers and similar classes that can hold user-defined
types;

2) pure swap, used by containers that hold only memory (e.g. QString,
QByteArray, ...) as well as most implicitly shared datatypes.

Given the fact that a move assignment operator's code is just
boilerplate (whether it's move-and-swap or pure swap), provide two
_strictly internal_ macros to help write them, and apply the macros
across corelib and gui, porting away from the hand-rolled
implementations.

The rule of thumb when porting to the new macros is:

* Try to stick to the existing code behavior, unless broken

* if changing, then follow this checklist:

  * if the class does not have a move constructor => pure swap
    (but consider ADDING a move constructor, if possible!)

  * if the class does have a move constructor, try to follow the
     criteria above, namely:

    * if the class holds only memory, pure swap;

    * if the class may hold anything else but memory (file handles,
      etc.), then move and swap.

Noteworthy details:

* some operators planned to be removed in Qt 6 were not ported;

* as drive-by, some move constructors were simplified to be using
qExchange(); others were outright broken and got fixed;

* some contained some more interesting code and were not touched.

Change-Id: Idaab3489247dcbabb6df3fa1e5286b69e1d372e9
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2020-10-03 11:47:17 +02:00
Edward Welbourne
533df067e9 Purge Q_{STDLIB,COMPILER}_UNICODE_STRINGS
These were now always defined, hence redundant.
Leave the #define in place so that we can verify we actually do always
define it, in a #else of an existing #if check on it.

Change-Id: Iea4c3dbc8f9982268bcf81da5ef17fe2ebf5c462
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2020-09-14 09:47:51 +02:00