Commit Graph

6386 Commits (cbb4aea2132fc59cd1086ba42cc221d12b5ce9e8)

Author SHA1 Message Date
Arno Rehn 59e21a536f QFuture: Don't use QFutureCallOutInterface for continuations
This patch replaces the QBasicFutureWatcher that was used for
continuations with context objects with a smaller QObject-based wrapper
that works directly from the actual continuation.
The idea stays the same: In order to run continuations in the thread of
a context object, we offload the continuation invocation to the
signal-slot mechanism.
Previously, we've hooked into QFuture with QFutureCallOutInterface to
emit a signal and trigger continuation invocation. However, it is much
easier and robust to emit that signal from the continuation itself.

This sidesteps the locking issues that QFutureCallOutInterface handling
presents. QFutureCallOutInterface basically requires any consumer to
only access the QFuture after all events have been posted and the
internal mutex unlocked, i.e. on the next cycle of the event loop.

Continuations do not impose this restriction; runContinuation()
explicitly unlocks the internal mutex before calling the continuation.

This fixes a deadlock when using QFuture::then(context, ...) where
the paren future is resolved from the same thread that the context
object lives in.

Fixes: QTBUG-119406
Fixes: QTBUG-119103
Fixes: QTBUG-117918
Fixes: QTBUG-119579
Fixes: QTBUG-119810
Pick-to: 6.7 6.6
Change-Id: I112b16024cde6b6ee0e4d8127392864b813df5bc
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-13 21:54:00 +01:00
Thiago Macieira 2b7908ac3a QBitArray: add rvalue binary bitwise operators
Now that the assignment-bitwise operators can reuse storage, we can make
these operators also be capable of reusing storage.

Pick-to: 6.7
Change-Id: I85b3fc2dd45c4693be13fffd1795b893de65a5b8
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-12 22:59:23 -08:00
Thiago Macieira 54c373faa4 QBitArray: improve memory allocation in the binary bitwise operators
Instead of creating a temporary copy of one of the two sides (which will
share QByteArray), create one with the correct target size such that it
is already detached.

Drive-by move them to hidden friends.

Pick-to: 6.7
Change-Id: I85b3fc2dd45c4693be13fffd1795b74eeaf3be71
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-12 22:59:23 -08:00
Marc Mutz f25804b395 tst_QtEndian: rewrite the ENDIAN_TEST macros to support FP
No functional change, yet. Just dissociating the data name from type
name, so we can add tests for FP types in a follow-up step.

Pick-to: 6.7 6.6 6.5
Change-Id: I98fdebb49cca614ab27db146c4bacafd190e7d9b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-12-11 23:40:04 +01:00
Marc Mutz fe8c8e0fce QDuplicateTracker: test with std::string, too
std::string is a nice value_type for when you want to track short
strings (because of its SSO). Check that it works, incl. in case
the implementation falls back to QSet in the absence of std::pmr
support in the stdlib.

Pick-to: 6.7 6.6 6.5
Change-Id: I2406258355295c2b1300c4ae8001cead59bb27d6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-12-11 19:00:16 +00:00
Marc Mutz 7a829eaf51 Fix return value of qbswap(qint128)
Should be qint128, not quint128.

[ChangeLog][QtCore][QtEndian] Fixed return type of qbswap(qint128)
(was: quint128).

No tests for this exist, so no wonder it fell through. Added them.

Amends befda1acca.

Pick-to: 6.7 6.6
Change-Id: Ibf87724b1d500081caca46af1c598975964e04c0
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-11 17:46:32 +00:00
Marc Mutz ca38ac7731 tst_QUuid: use int128 literals and QCOMPARE support
When the test was written, we didn't have support for either int128
literals or proper QCOMPARE failure printing (QTest::toString()), so
the code awkwardly constructed literals from 64-bit ones using
arithmetic and QCOMPAREed the high and low 64-bit halves separately.

Now that we have added support for both, simplify the test code
accordingly.

Change-Id: Icdee7bb01f6e4bd3de74233b4fb992b0590ddafd
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-12-09 21:00:16 +01: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 28f1eb6c83 tst_QGlobal: work around ubsan issue in toString(qint128)
Found a problem on GCC 9.4 where asan/ubsan seems to break
std::numeric_limits<int128>::min():

    runtime error: negation of 0x80000000000000000000000000000000 cannot be represented in type '__int128'; cast to an unsigned type to negate this value to itself

This is the -i _after_ we've already checked for ::min() two lines
above. It works with Q_INT128_MIN, though, so use that.

Pick-to: 6.6
Change-Id: I778980baf4e7eea9f8de06697d792241314acacd
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-12-09 05:29:23 +01:00
Po-Hao Su 311f889632 QProperty: clean up unnecessary sentinel class
Instead of introducing the nested class InheritsQUntypedPropertyData
as a sentinel class for inheritance check, we can use BinaryTypeTrait
to handle the check. By doing this, we no longer need to maintain the
nested class.

Change-Id: Ie3aae976015d5fae6b6d072cad6ee52cd30b769d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-12-09 08:37:44 +08:00
Thiago Macieira ead408ca1b QMetaType: fix typenameHelper() for types in the QtPrivate namespace
GCC at some point decided that it wouldn't include the full namespace
expansion in __PRETTY_FUNCTION__ for any type that is in the same
namespace as the template function being expanded (that is, the
QtPrivate) namespace. I don't know how long this behavior has been in
place, but it can be seen with GCC 13, where the expansion of that macro
inside QtPrivate::typenameHelper<QtPrivate::ModelIndex>() is:

 constexpr auto QtPrivate::typenameHelper() [with T = ModelIndex]

This can be easily worked around by using a different namespace.

Fixes: QTBUG-119650
Pick-to: 6.6 6.5 6.2
Change-Id: Ica7a43f6147b49c187ccfffd179df309e43a70cb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-12-08 14:03:55 -08:00
Ivan Solovev 0d85d0a72f qfloat16: extend comparison with integral types
qfloat16 implemented comparison with int, but not with other integral
types. As a result, comparing qfloat16 vs qint64 or short was
ambiguous, because the compiler had (at least) two options:
* qint64 -> int
* qint64 -> float

Fix it by explicitly introducing comparison operators for other integral
types.
Use the new compare helper macros for that, and implement helper methods
as templates restricted on integral types.

Note that we have to manually extend the std::is_integral type trait
because libstdc++ only treats __{u}int128_t types as integral when
compiling in -std=gnu++XX mode, and we compile Qt in -std=c++XX mode.

Fixes: QTBUG-117637
Change-Id: Id0c074af1e9ccc2c2492eb2cc4ee62a4a7131b07
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-12-08 14:53:37 +01:00
Ivan Solovev e1eec6476a qfloat16: use new comparison helper macros
This replaces all the other helper macros which were used to
generate the relational operators before, and also gains support for
operator<=>() in C++20 mode.

Change-Id: I40cec3cb5a5c42523787414d610e00afe6fc86f8
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-08 14:53:37 +01:00
Edward Welbourne 41f84f3ddb Give the caller control over the century used for two-digit dates
The twentieth century is now some way behind us, so using its years
when parsing a date-time format that only provides the last two digits
is increasingly likely to produce unwelcome results. Most such formats
are saved by the "redundant" presence of a day-of-week field but, for
those that are not (notably including ASN.1 date fields), there is a
need to provide some way to over-ride the twentieth century default.

Allow the caller to pass a base year to the fromString() methods, of
QDate and QDateTime, and to QLocale's toDate() and toDateTime(), that
indicates the first of 100 consecutive years, among which the two
digits given can select a year. Add some test-cases to exercise the
new API.

[ChangeLog][QtCore][QDate] When fromString() has only a two-digit year
to go on, it is now possible to set the start-year of the century
within which this selects.

[ChangeLog][QtCore][QDateTime] When fromString() has only a two-digit
year to go on, it is now possible to set the start-year of the century
within which this selects.

[ChangeLog][QtCore][QLocale] When toDate() or toDateTime() has only a
two-digit year to go on, it is now possible to set the start-year of
the century within which this selects.

Fixes: QTBUG-46843
Change-Id: Ieb312ee9e0b80557a15edcb0e6d75a57b10d7a62
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-12-08 11:40:36 +01:00
Edward Welbourne b8fac53803 Add QCalendar::matchCenturyToWeekday()
This takes a YearMonthDay and a day-of-the-week, returning a QDate
that (if possible, else invalid) has the given day of the week and
differs from the YearMonthDay only in the century. This is useful when
resolving dates with only two-digit year information, which can be
disambiguated by the day of the week. Added tests of the new API.

This adds a new virtual method to QCalendarBackend, for which that
base class does provide a brute force implementation, so derived
classes do not need to add implementations. It is, however, a
binary-incompatible change for any backend plugins that may be in use
to implement custom calendars.

Worked out the details for the Gregorian calendar to make it possible
to compute the right century (and whether any century works) without
trial-and-error searching. Coded that up as its implementation of the
new method.

[ChangeLog][QtCore][QCalendar] Added a matchCenturyToWeekday() method
for use when resolving dates given day, month and last two digits of
the year, along with day of the week. Any custom calendar backend
plugins shall need a recompile and may, optionally, implement the new
virtual method behind this.

Change-Id: I6003c8d9423d6bfb833957bb5120f2d423219c7a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-12-08 11:40:36 +01:00
Rym Bouabid 4fa9f13397 Make QAtomicScopedValueRollback public API
Move the private header to public.
Make documentation a part of public interface.

[ChangeLog][QtCore][QAtomicScopedValueRollback] New class.

Task-number: QTBUG-115107
Change-Id: I6c9f5448e74a5b62f4d97ee079944f4b1b731121
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-08 02:24:41 +01:00
Marc Mutz 6c60117d01 tst_QString: explain TransientDefaultLocale better
A default-constructed QLocale gets initialized with the
currently-active default locale, and apparently retains that setting
henceforth. That is why the `prior` member is not explicitly
initialized, which is confusing at face value.

Explain the mechanism better, and explicitly default-initialize the
member, so the next reader of the code saves the time to research
this.

Amends 76dfda1ad1.

Pick-to: 6.6 6.5 6.2 5.15
Change-Id: I1d1171f8564c70a971938b92b809f63ba5637d3a
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-12-07 23:55:08 +01:00
Marc Mutz 0a86a77e5f tst_containerapisymmetry: remove the extra push_back
... and make sure it cannot happen again by using Extract Method to
let the compiler do the counting between the resize and the
sequence-of-push_back alternatives, because this author clearly can't.

Amends 3c0fdd7341.

Pick-to: 6.6 6.5
Change-Id: If18f30d60f556e5e668876a38423f3e519fb79b0
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-12-07 23:55:08 +01:00
Thiago Macieira db991cb4e1 QBitArray: replace the member operator~ with a hidden friend
Which takes the array to be inverted by value, so we get free move
semantics and allowing us to perform the negation in-place.

[ChangeLog][Potentially Source-Incompatible Changes] The bitwise AND,
OR, XOR, and NOT operator functions on QBitArray are now hidden
friends. This may cause source-incompatibility in unusual coding styles
(like 'array.operator~()') or with classes that have a casting 'operator
QBitArray()'.

Change-Id: I85b3fc2dd45c4693be13fffd1795ba1fbaf23769
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-07 14:55:07 -08:00
Marc Mutz 03e78e5d62 Long live QSpan as public API!
Provide qspan_p.h as backward-compatibility header.

[ChangeLog][QtCore][QSpan] New Qt equivalent of std::span.

Fixes: QTBUG-115022
Change-Id: I1cc27dc0aa1f7406f0a41d7a75f176cd7f858feb
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-12-07 22:38:15 +00:00
Marc Mutz c39fff0da5 Add missing <=> 0 operator to Qt ordering types
It's required by the standard, see e.g. [1] and the eel.is links in
the code.

[ChangeLog][QtCore][QPartialOrdering] Added three-way comparison
operator (<=>) against literal zero, available when compiling in C++20
mode.

[1] https://en.cppreference.com/w/cpp/utility/compare/partial_ordering#Comparisons

Change-Id: I8a3b76661400930c6e247cf5b138ff52bf784395
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-07 23:36:15 +01:00
Marc Mutz ccd0dc7f6d QPartialOrdering: add lower-case flags for std/Qt:: compatibility
The misspelt flags (Less, etc) make it hard to use QPartialOrdering
interchangably with Qt or std ordering types, e.g. in generic code.

[ChangeLog][QtCore][QPartialOrdering] Added a set of lower-case flags
(::less, ::greater, etc) to improve source-compatibility with
{Qt,std}::partial_ordering.

Change-Id: I160600c01c4a2ab72c7b217a306d08045e363578
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-07 23:36:15 +01:00
Marc Mutz 07ed8acdf9 QPartialOrdering: add missing conversions to/from Qt::_ordering types
Since QPartialOrdering is supposed to be a drop-in-replacement for
Qt::partial_ordering, it need to have the same conversions from
Qt::_ordering types that Qt::partial_ordering has.

Fix by adding the necessary conversion and relational operators and
conversion constructors.

Change-Id: Ib8e78c850b43c8bcb3bb15c5f7d25be9d0da7339
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-07 23:36:15 +01:00
Marc Mutz a0ae96e3e7 QPartialOrdering: add missing conversion from std::{weak,strong}_ordering
QPartialOrdering is suppsed to be a drop-in replacement for
std::partial_ordering, so it has to be convertible from all
std::_ordering types.

It was, however, only convertible from std::partial_ordering, and two
user-defined conversions in a row are not allowed.

Add the missing constructors. They, in turn, can then delegate to the
partial_ordering constructor.

Change-Id: I085d95677b258b4a61aabfd5468c1c43c2212766
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-07 23:36:14 +01:00
Ivan Solovev 3d231e27a8 Long live qCompareThreeWay()
qCompareThreeWay() is a top-level wrapper around the helper
three-way comparison methods, which is mostly convenient for
generic client code.

When implementing compareThreeWay() for Qt types, we normally
provide the implementation only for (LeftType, RightType) pair,
but not the reversed one.
However, it is expected that qCompareThreeWay() would be available
for both combinations, because the reversed result can be easily
calculated.
Solve it by providing a helper hasCompareThreeWay<LT, RT> variable
and branching the implementation based on its value.

The noexcept check is inspired by the old implementation of qSwap().

[ChangeLog][QtCore] Added qCompareThreeWay() as a public API for
three-way comparison.

Task-number: QTBUG-104113
Change-Id: I6f24494d968c336f3dcdf620004b4190769cbdb2
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-07 23:36:14 +01:00
Marc Mutz 2d052b038d Check that QMulti{Map,Hash} (still) store in reverse insertion order
It's wrong, but let's not break it unconsciously.

Pick-to: 6.6 6.5
Change-Id: Ic3daa7df4db2ef34ff5d08fddecf9a932ad92156
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2023-12-07 07:16:23 +02:00
Marc Mutz 3c0fdd7341 tst_ContainerApiSymmetry: check value_types with a const member
QVarLengthArray is the only Qt container currently known to be fine.

std::vector is supposed to be fine, too, since C++14. Turns out that
libstdc++ gets resize(n, v) wrong, though, because it never
implemented the resolution to wg21.link/lwg2033. Known issue, linked
in code comment. Worked around for the time being. Keeping std::vector
in, though, because in this test suite we do cross-check with
std::vector, and other platforms, and most of GCC's std::vector
functions, adhere to the standard.

Pick-to: 6.6 6.5
Change-Id: I26e11c4a100695c604cebcf7e14a1ae5078d9ec7
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-12-07 06:16:23 +01:00
Marc Mutz 5f775e6719 Fix QStringConverter::encodingForName() for trailing `-`, `_`
The (internal) docs say that - and _ are ignored, and they're ignored
everywhere, except as suffixes. If the old code only ignored them as
infixes, fine, that would make some sense, but it ignored infixes and
prefixes, so there's no reason for it to not ignore suffixes, too.

Fix by continuing the loop until both input ranges are exhausted, or a
mismatch was found.

[ChangeLog][QtCore][QStringConverter] Fixed a bug where
encodingForName() failed due to trailing characters (`_`, `-`) that
ought to have been ignored.

Pick-to: 6.6 6.5
Change-Id: Iec21489d988eda7d33c744c170f88cd665b73f34
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-07 05:16:23 +00:00
Marc Mutz 091793ccaa qcomparehelper.h: simplify compareThreeWay() SFINAE helpers
There's no restriction on the number of enable_if's in a
template-initializer, so simplify the compareThreeWay() constraints by
having separate constraints each for LeftType and RightType. Fewer
templates to instantiate = faster compile speed.

As a drive-by, drop remove_reference_t. We control all users and all of
them pass already-decayed types.

Change-Id: I17c01c7aa1ac03bb6db4b0bef1371ebc0641641d
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-07 06:16:23 +01:00
Ivan Solovev 4b755bc11a Teach Qt::compareThreeWay() to support native float16 types
Provide a custom variable template to detect float types and
specialize it for QtPrivate::NativeFloat16Type.
This will allow to enable three-way comparison for qfloat16.

Task-number: QTBUG-104113
Change-Id: Id12c42c86f8dc9e233fe39776b0f0e28088de9e1
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-07 06:16:23 +01:00
Marc Mutz 7f5b795f75 QSpan: ensure interoperability with std::span
We accepted QSpan as a NIH-type instead of waiting for C++20 and
std::span, because we said that there's no impedance mismatch between
the two, as they both implicitly convert into each other.

But we actually never checked that they do.

Fix this omission by adding constructors that treat std::span exactly
the same as QSpan itself, and adding the respective static_assert()s
to tst_QSpan to check that (within the constraints imposed by the
standard on std::span), they actually do convert into each other.

The only two problematic cases are that fixed-size std::span
constructors are explicit, so span is only constructible, not
convertible, from QSpan. Likewise, for an rvalue QSpan to be
acceptable to the std::span constructor, QSpan needs to opt-in to
enable_borrowed_range (while we're at it, do enable_view, too).

We so far have rejected adding these opt-ins for our own container
classes because we wanted to avoid the compile-time overhead of
including the huge <ranges> header into such central headers as those
that define our containers.

But std::span itself has to specialize these traits, and its range
contructor has to use them, so they must be available from <span>,
too, possibly the stdlib puts the definition into a much smaller
header. So just assume we can specialize it after including just
<span>, provided __cpp_lib_concepts is also defined.

Pick-to: 6.6
Change-Id: I2202869b60c98047256b0fbcb12336f5d8e550ba
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-12-07 02:46:22 +01:00
Marc Mutz c851fb2456 QSpan: check conversion from initializer_list
The docs at cppreference.com hint at a corresponding ctor being added
for C++26 (though I don't see it in eel.is/c++draft, yet).

Even so, replacing former initializer_list functions with QSpan ones
is definitely one of the upcoming use-cases, so test it.

Can't use from_container_impl() here as initializer_list<T> is already
immutable, so QSpan<int> is not compatible, only QSpan<const int>.

Pick-to: 6.6
Change-Id: Iecdf29e629d48313edd5e56d358b9137da76deb6
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-12-07 02:46:13 +01:00
Christian Ehrlicher d4d40aee94 Tests: remove blacklisted CIs no longer available
Remove the following CIs from BLACKLIST files as they are no longer
used:
  - msvc-2015
  - msvc-2017
  - windows-7sp1
  - opensuse-42.3
  - ubuntu 16.04/18.04/20.04
  - rhel 6.6/7.4/7.6
  - redhatenterpriselinuxworkstation-6.6

Change-Id: Ief9550e3455a1ed211d978933262c8d5557b0fec
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-12-06 22:07:44 +01:00
Marc Mutz 6e41101217 tst_QCompare: restore some test coverage to QPartialOrdering
When I split Qt::partial_ordering off of QPartialOrdering, O
duplicated the partialOrdering() test, but lost the conversion() part
of the tests.

This patch brings them back.

Because we maintained the test coverage for Qt::partial_ordering, it
suffices to check that QPartialOrdering::X correctly maps to
std::partial_ordering::x. The rest follows from transtivity of
equality.

We're still lacking conversions of QPartialOrdering to Qt::_ordering
types. That will be the subject of a follow-up patch.

Amends 4b6f757020.

Change-Id: I1938d09f696ed8d58143dbacccb72cfd54ca12dd
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-05 23:04:30 +01:00
Marc Mutz ee623402df tst_QCompareHelpers: extract Qt/std-mapping into public header
We'll need this elsehere, too.

Change-Id: I91a35a23dd201f7867898cee5b4d6743883f71fc
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-12-05 22:56:45 +01:00
Assam Boudjelthia 7a9bc220c7 Android: fix and simplify the orientation change logic
Move the orientation change handling to the display manager
and call it from the relevant places to repeated and scattered
code for the same functionality.

Bring back part of 072387edec
which checks discard a resize event that's not valid that
reports not up to date layout size.

If DisplayManager.DisplayListener.onDisplay() initiates the
orientation change, handle it immediately if we don't expect
the size to change, i.e. if the orientation is changing from
portrait to inverted portrait and vise versa for landscape.
Otherwise, expect the change to be initiated again shortly
after from QtLayout.onSizeChanged().

Also, add improve the unit test of the orientation change,
and test for the widget size after such changes to make
sure QTBUG-94459 is not reached again.

Fixes: QTBUG-119430
Task-number: QTBUG-115019
Task-number: QTBUG-94459
Change-Id: I5f060d91531af677ddf891f2af360d5f399e26e5
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2023-12-05 16:28:12 +00:00
Ivan Solovev 7a3fed3f20 QTimeZone: use new comparison helper macros
The class had operator==() and operator!=() defined as public member
functions, so use QT_CORE_REMOVED_SINCE and removed_api.cpp to get
rid of these methods and replace them with hidden friends.

Extend unit-tests by using the helper functions from QTestPrivate.

Task-number: QTBUG-104111
Change-Id: Ib9ca613005e2f1521dea5e3cd9e2baa0b47fede4
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-28 21:30:58 +01:00
Ivan Solovev 96f494bf92 Implement helper Qt::compareThreeWay() function for built-in types
The helper function

 RetType compareThreeWay(const T &left, const T &right) noexcept;

is used for C++20-comparison macros. Normally it's the user's
responsibility to provide this function as a hidden friend of the class
which uses the comparison helper macros.
For built-in types we provide the implementation inside the Qt
namespace.

We have to use custom IsIntegralType trait because libstdc++ only
treats __{u}int128_t types as integral when compiling in -std=gnu++XX
mode, and we compile Qt in -std=c++XX mode.

This patch provides the implementations only for compareThreeWay()
overloads, because there is no need to implement comparesEqual() for
built-in types. It would just be equivalent to calling operator==(),
so the user can do it directly.

Task-number: QTBUG-104113
Change-Id: I7b3f395458e1ee4c64f442ad48bbf4fec4c19c52
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-11-28 21:30:33 +01:00
Ivan Solovev fe12650e9d Implement compare helper macros
These macros should unwrap into a proper set of equality and ordering
operators, depending on the C++ standard being used.
For C++17, all 6 operators (==, !=, <, >, <=, >=) are overloaded, while
for C++20 only the overloads for opeartor==() and operator<=>() are
provided.

The macros are documented as internal for now.

The macros rely on two helper functions:
  bool comparesEqual(LeftType lhs, RightType rhs);
  ReturnType compareThreeWay(LeftType lhs, RightType rhs);

The comparesEqual() helper function is used to implement operator==()
and operator!=().
The compareThreeWay() helper function is used to implement the four
relational operators in C++17, or operator<=>() in C++20.
ReturnType must be one of Qt::{partial,weak,strong}_ordering.
When possible, the functions should also be declared constexpr and
noexcept.
It's the user's responsibility to provide the functions before
using the macros.

Implement a test case which applies the new macros to the dummy
classes, and uses the new helper function to verify the comparison
results.

The MSVC compiler before version 19.36 has a bug, where it fails
to correctly generate reverse opeerators in C++20 mode. Introduce
a new Q_COMPILER_LACKS_THREE_WAY_COMPARE_SYMMETRY definition for such
compiler versions, and use it to manually generate reversed
operators when needed.

Task-number: QTBUG-104113
Change-Id: Idc19d55df011fd616ff654f35a964e831b8ab93b
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-11-28 20:30:19 +00:00
Edward Welbourne 5108192f67 Clean up QDate(Time)?::fromString() test-data tables, adding a column
The new column is currently unused, added for the benefit of an
imminent change, but adding its value was going to change every data
row, making the new rows with a different value there hard to see amid
the diff.

So add the unused value to the existing data rows and clean them up in
the process:
* Use modern string literals
* Split lines (that need it) in a consistent way
* Give test-cases not-entirely-meaningless names.

Change-Id: I9abdd24b7bb945796878c664d2ed82ca6c409fc1
Reviewed-by: Isak Fyksen <isak.fyksen@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-11-28 19:59:49 +01:00
Thiago Macieira 878e3342e1 QFactoryLoader: add metaDataKeys() to return just the "Keys" entry
Without parsing the whole metadata structure into a QCborValue.

QFactoryLoader::indexOf() is only used in the icon engine and
accessibility loaders. QFactoryLoader::keyMap() has more users, but
QFactoryLoader::metaData() is still by far the most used interface.

Task-number: QTBUG-114253
Change-Id: I8bd6bb457b9c42218247fffd179753524fc9b6a5
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-11-28 03:14:03 -08:00
Thiago Macieira 4a432a7617 QFactoryLoader::instance(): don't fully parse static plugins' data
Commit d9766ddc3d (Qt 5.12) replaced the
use of the old binary JSON format with CBOR, which is more compact and
standard, but requires actual parsing instead of just a quick size
verification. For regular, loaded plugins, the metadata is stored in
parsed QCborValue format, but for static plugins, we were re-parsing
each staticplugin's metadata for every single call.

This avoids a full parsing and only parses the CBOR header to find the
IIDs (moc always outputs the IID first).

Fixes: QTBUG-114253
Pick-to: 6.6
Change-Id: I8bd6bb457b9c42218247fffd179750ec6c9e3252
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-11-28 03:14:03 -08:00
Marc Mutz 4b6f757020 Make Qt::partial_ordering binary-compatible to std::partial_ordering
In particular, match the value of ::unordered to each std library
implementation.

Legal disclaimer:

The values were provided to this author in a comment on QTBUG-118913.
This author hereby confirms he didn't look at any of the
implementations himself. The stdlib detection macros are taken from
existing code in qcompilerdetection.h. I didn't succeed in googling a
corresponding marker for MSSTL, and I didn't look at the
implementation or Boost.Config to find one, so this patch just assumes
MSSTL as a fall-back, which is probably wrong, since we may still have
Dinkumware and RougeWave STLs to deal with on embedded platforms.

Add tests to ensure the values are the same on all platforms.
To maximize coverage, rename qcompare.qdoc to qcompare.cpp and add a
bunch of compile-time tests there. These depend in part on bit_cast,
which we cannot depend on, so tst_qcompare contains the same tests
using memcpy.

Fixes: QTBUG-118913
Change-Id: I46c922c8e3ea37d7c01a71361c7a689340f9047d
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-11-27 18:34:10 +01:00
Ahmad Samir 9e6c9eda6f QMetaEnum: let key(s)ToValue match fully-qualified unscoped enumerators
For an unscoped enumerator, e.g.:
namespace N {
    class C {
        enum E { F };
    };
};

N::C::F and N::C::E::F are equivalent and key(s)ToValue should match
both.

This already works for scoped enums because the name of the enum can't
be dropped.

Fixes: QTBUG-118240
Pick-to: 6.6
Change-Id: I84d7bbb7aa8f82b2a7c2bc7e4edd5d77d37335c4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-11-26 22:51:49 +02:00
Thiago Macieira 1d9137e13f QCborStreamReader: add UTF-8 reading API
Change-Id: I8bd6bb457b9c42218247fffd1797605d1687b0dc
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-11-24 12:42:12 -08:00
Thiago Macieira 8af346c1f6 QCborStreamReader: add toString() and toByteArray()
They've been a long time coming. I had them in TinyCBOR before the
chunked reading; in fact, I added the chunked reading specifically for
Qt's CBOR support.

[ChangeLog][QtCore][QCborStreamReader] Added toString() and
toByteArray(), which read a full string whether it is chunked or
not. They also guard against attempting to allocate more memory than the
underlying stream could provide.

Change-Id: Icfe44ecf285a480fafe4fffd174c5815f153d5b5
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-11-24 12:42:12 -08:00
Edward Welbourne 7befd4cad4 Purge empty BLACKLIST files from tests
There's no point to the file if it has no content.

Change-Id: Ie0deb59a63d5f7a654fcab1218e0a814710072ff
Reviewed-by: Jason McDonald <macadder1@gmail.com>
2023-11-24 18:09:16 +01:00
Edward Welbourne 9f3ae15933 Add a comment to tst_qtimer.cpp to point out its reuse by QtGui
The same test code is compiled by two different modules' tests, which
won't be obvious to the reader of the code unless it's pointed out
explicitly.

Change-Id: I99dba6eb186939c372636c5c1fc29799003d32a7
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-11-24 15:37:17 +01:00
Piotr Wierciński dabf8a0d89 wasm tests: Disable unstable qcborvalue test
Change-Id: Idd22897a7ecb4c5e28d60acf390d65517f89c05a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-11-23 19:26:49 +01:00
Volker Hilsheimer d2c6e9ab99 Blacklist tst_QGuiEventLoop::processEvents on QNX
The test log shows flaky failures of this test several times a day on
QNX, so blacklist it.
To do that, we need to be able to isolate the "GUI" mode of this test.
To do that, add a single data tag that depends on whether the test
project is built for GUI or Core, and blacklist only the "gui" data tag.

Task-number: QTBUG-119359
Pick-to: 6.6
Change-Id: I91c2380de0a3febedcf781f27fed4a1fa6aa5515
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-11-22 21:15:38 +01:00