summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global
Commit message (Collapse)AuthorAgeFilesLines
* ptests: Fix qlogging to use relative folderAri Parkkila12 hours2-4/+1
| | | | | | | | | | Run qlogging_helper at relative working directory because CMAKE_CURRENT_BINARY_DIR is not valid when test is run after installed from package to target. Task-number: QTBUG-118680 Change-Id: Ifd46d05562006ad4adf17517fae30ca5c63bc157 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* CMake: fix cross-compilation build: ${CMAKE_SYSTEM_PROCESSOR} is emptyThiago Macieira9 days1-1/+1
| | | | | | | | | | | | | | | | CMake Error at tests/auto/corelib/global/qcomparehelpers/CMakeLists.txt: 20 (if): if given arguments: "CMAKE_VERSION" "VERSION_GREATER_EQUAL" "3.20" "AND" "NOT" "MACOS" "AND" "NOT" "VXWORKS" "AND" "NOT" "(" "LINUX" "AND" "MATCHES" "aarch64" ")" Unknown arguments specified Pick-to: 6.7 Change-Id: I6979d02a7395405cbf23fffd17c900d8e25e4c0c Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QKeyCombination: use new comparison helper macrosTatiana Borisova2024-04-172-40/+29
| | | | | | | | | | Replace public friend operators operator==(), operator!=() of QKeyCombination to friend method comparesEqual() and Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE macro. Task-number: QTBUG-120304 Change-Id: I679f3fa5fcc4c675a763cc5a5fe0e0880439a64f Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Skip tst_qcomparehelpers_cpp23 on Linux armIvan Solovev2024-04-121-1/+1
| | | | | | | | | Because it causes issues in the CI Pick-to: 6.7 Change-Id: I8cd232abf1c4ee1d9417a8bff9aa3bcf5f893e8f Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Revert "QTypeInfo: add detection for Clang's __is_trivially_relocatable"Tor Arne Vestbø2024-03-221-14/+0
| | | | | | | | | This reverts commit f4bac3ca173be9f219099c04e76d6d62c4d0e19e. It broke builds with Xcode 15 Change-Id: Iee232658ede3dfb09d65f3f6a95410c069941421 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QTypeInfo: add detection for Clang's __is_trivially_relocatableGiuseppe D'Angelo2024-03-221-0/+14
| | | | | | | | | | Types marked with [[clang::trivial_abi]] are considered to be trivially relocatable for Clang. This is ABI compatible, since in Qt 6 we can change the value of QTypeInfo::IsRelocatable "after the fact" -- it simply means that code that doesn't get recompiled is pessimized. Change-Id: I32e52bfb212c7919b2ebcf7832ede4404358330f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tst_qglobal: add a few tests for QTypeInfoGiuseppe D'Angelo2024-03-221-0/+49
| | | | | Change-Id: Iff4d8d9488d5b414d4504bc700b3191c799bf86c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tst_qglobal: include what you useGiuseppe D'Angelo2024-03-221-1/+2
| | | | | | | | Fix the inclusions of stdlib headers to what is actually used in the test. Change-Id: I03ad4bdfd0b036bc4cee65b6bd2cd43ac7449722 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix build of tst_qoperatingsystemversion.cpp with C++20Joerg Bornemann2024-03-191-2/+2
| | | | | | | | | The QCOMPARE_EQ macro was mistyped. This amends commit 5ea434b09f6a760b84fb14a69cc578063cad99a1. Change-Id: I313eb5ef02bb2266d659bdbe41d7d8f10691e0ca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix truncation warnings in tst_qnumericIsak Fyksen2024-03-161-1/+1
| | | | | | | | | | | Add `f`-suffix to float assignments to avoid implicit conversion from double to float. Fixes: QTBUG-122303 Change-Id: I456e2952fe8c96783ab116ac4cb56a28b38de9d0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix overflow warnings in tst_qnumericIsak Fyksen2024-03-161-0/+3
| | | | | | | | | Suppress compiler warning on intended behavior. Fixes: QTBUG-122304 Change-Id: Ic093201ea766caec1df01afcc3b0af15d0f72963 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* CMake: Make a few more auto tests standaloneAlexandru Croitor2024-03-141-0/+6
| | | | | | Pick-to: 6.7 Change-Id: I80988114bd906447a2ab712d5432a489e095a5c1 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* QOperatingSystemVersion: use partial ordering for relational operatorsIvan Solovev2024-03-131-55/+52
| | | | | | | | | | | | | | | | | | | | | | QOperatingSystemVersion intentionally does not define operator==() and operator!=() since ae072cd9c4a575e0ed3f073c6ab395ccdf7c2b37. It means that we cannot use comparison helper macros. Still, we can manually define four relational operators or operator<=>() in C++20 mode, and give the class a partial ordering. We choose partial ordering, because versions of different OS types are incomparable. Implement the operators in terms of helper function compareThreeWay(), which potentially allows to use this class in some templated code. As a drive-by: make the static compare() function noexcept, because it really is. Fixes: QTBUG-120360 Change-Id: Id4c9ce740e42baa719ca0ee84146d087b21675c6 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tst_qmessagehandler: disable the backtrace tests outside of x86Thiago Macieira2024-02-261-2/+5
| | | | | | | | | | | | | | | | | | | | | As the comment says, on most RISC platforms, the return address need not be on the stack in the first place. In fact, in all ones currently supported by Qt, it's passed in a register to the callee, which has the option of simply saving it in a callee-save register when calling leaf functions. Even if it is using a frame pointer, the compiler can simply use any register. That means unwinding the stack is not possible in the absence of either debug information or stack-unwind information, neither of which backtrace(3) will use. Strictly speaking, even on x86 the compiler can use the RBP register for any purpose and thus make getting the backtrace() impossible, but in practice it seems to work. Fixes: QTBUG-121389 Pick-to: 6.7 Change-Id: I5dd50a1a7ca5424d9e7afffd17acbd01ef916f5d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Comparison helper macros: add an Attributes parameterIvan Solovev2024-02-203-4/+64
| | | | | | | | | | | | | Some of relational operators in Qt are marked with QT_ASCII_CAST_WARN (see e.g. String, QLatin1StringView). If we want to convert these operators to the new comparison helper macros, we need a way to preserve this attribute. My tests show that simply adding the attribute to the helper comparesEqual() and compareThreeWay() functions does not work, so we need to explicitly add it to each of the generated operators. Change-Id: I2940a70fe191326e8a2ebfb05b8da6e0f21a845c Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Refactor tst_qcomparehelpersIvan Solovev2024-02-164-188/+255
| | | | | | | | | | | | | | | | | Previously the test consisted of just one cpp file. An attempt to add more test cases to the file resulted in the minGW compiler complaining about a too large object file: Fatal error: tst_qcomparehelpers.cpp.obj: file too big This patch splits the implementation into a header and a cpp file. This itself does not fix the issues, but now we can add the new test cases in a separate cpp file. This patch also adds some comments that advocate doing so. Pick-to: 6.7 Change-Id: I451987370fa4e18b7ad81dfc064ea016f1d0da47 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Change license for tests filesLucie Gérard2024-02-0422-22/+22
| | | | | | | | | | | | According to QUIP-18 [1], all tests file should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* Exclude VxWorks from cxx 23 mode compilation of qcomparehelpersKrzysztof Sommerfeld2024-01-311-1/+1
| | | | | Change-Id: Ia217a76ad96851a3ad9dedae4ab3ff1c2b3b92c6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Un-blacklist QMessageLogger backtrace tests for b2qt 64bitJoerg Bornemann2024-01-221-4/+0
| | | | | | | | They are working fine by now. Change-Id: I24b1ac61791a850da85347c9718df678dfea2706 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Blacklist QMessageHandler backtrace tests for b2qt 32bitJoerg Bornemann2024-01-221-2/+4
| | | | | | | | | | Un-blacklist tests/auto/corelib/global/qlogging for Boot2Qt+CMake, since we only have a CMake build by now. Task-number: QTBUG-90545 Task-number: QTBUG-121389 Change-Id: Ia9d5fb2344598d58e06595c9cef93d5bba3de0cb Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* qfloat16: make relational operators constexpr when QFLOAT16_IS_NATIVEIvan Solovev2024-01-191-0/+40
| | | | | | | | | | | | | | | | | | | When qfloat16 uses float as an underlying type, the operators cannot be constexpr, because operator float() is not constexpr. However, operator NativeType() is, so we can make the relational operators constexpr when we are using a native 16-bit float as an underlying type. To avoid code duplication, introduce new temporary macros for constexpr and Q_DECLARE_PARTIALLY_ORDERED_LITERAL_TYPE. Extend the tests to verify that the operators are constexpr when native float16 type is used. Task-number: QTBUG-119433 Pick-to: 6.7 Change-Id: I001b087d78c398c71b71a504b65c316199dd4792 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Introduce macros to simplify testing comparisonIvan Solovev2024-01-191-7/+2
| | | | | | | | | | | | | | | | | | | | | The problem with the QTestPrivate::testAllComparisonOperators() and QTestPrivate::testEqualityOperators() functions is that if they fail, they point into the helper function, but not into the actual test that called the helper function. This is specially annoying when some test calls the helper function multiple times. This patch introduces the helper macros QT_TEST_ALL_COMPARISON_OPS and QT_TEST_EQUALITY_OPS that wrap the respective function calls together with the QTest::currentTestFailed() check. If the test has failed, the macro generates a meaningful debug message with the original file name and line number. This patch also applies the new macros to qtbase. Task-number: QTBUG-119433 Pick-to: 6.7 Change-Id: Iad709de45e5bf53c82e7afa8e9f51e9275c1e619 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* tst_QCompareHelpers: fix narrowing warningMarc Mutz2024-01-121-8/+8
| | | | | | | | | | | | | | | | | | Warns MingW (or, in general, any GCC 13): warning: converting to 'QtPrivate::NativeFloat16Type' {aka '_Float16'} from 'double' with greater conversion rank See also a61d7529511c890aa595110b9320ea0bf53dd623. Fix by using ints instead. As a drive-by, make the variable constexpr. Amends 4b755bc11a8eadd156c65b7474c11e3ce822c6f1. Pick-to: 6.7 Change-Id: Ie3f3c51aa7e9323c7ba96c810d2e95247d222fd2 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* tst_qxp_function_ref: check that function_ref's are trivially copyableMarc Mutz2023-12-161-0/+2
| | | | | | | | | | | | | Mandated by P0792R9 already, but we never checked and P0792R14 has user-defaulted assignment operators showing up in the synopsis now, so make sure we don't accidentally break this going forward. Amends 29b65c98e720056e87334ce88a683969e57efd3d. Pick-to: 6.7 6.6 6.5 Change-Id: Ief9c5ff30895f8bfccec1c24d1777d3dab76c95a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* tst_QtEndian: rewrite the ENDIAN_TEST macros to support FPMarc Mutz2023-12-111-30/+32
| | | | | | | | | 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>
* Fix return value of qbswap(qint128)Marc Mutz2023-12-111-0/+29
| | | | | | | | | | | | | | | 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 befda1accab417ce5f55cb11816e6ded51af55e3. Pick-to: 6.7 6.6 Change-Id: Ibf87724b1d500081caca46af1c598975964e04c0 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Long live QDebug::operator<<(q(u)int128)!Marc Mutz2023-12-091-40/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* tst_QGlobal: work around ubsan issue in toString(qint128)Marc Mutz2023-12-091-1/+1
| | | | | | | | | | | | | | | 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>
* qfloat16: extend comparison with integral typesIvan Solovev2023-12-081-4/+35
| | | | | | | | | | | | | | | | | | | | | | | 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>
* qfloat16: use new comparison helper macrosIvan Solovev2023-12-081-0/+105
| | | | | | | | | | 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>
* Add missing <=> 0 operator to Qt ordering typesMarc Mutz2023-12-071-0/+68
| | | | | | | | | | | | | | | 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>
* QPartialOrdering: add lower-case flags for std/Qt:: compatibilityMarc Mutz2023-12-071-0/+5
| | | | | | | | | | | | 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>
* QPartialOrdering: add missing conversions to/from Qt::_ordering typesMarc Mutz2023-12-071-0/+1
| | | | | | | | | | | | 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>
* QPartialOrdering: add missing conversion from std::{weak,strong}_orderingMarc Mutz2023-12-071-0/+2
| | | | | | | | | | | | | | | 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>
* Long live qCompareThreeWay()Ivan Solovev2023-12-071-0/+113
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* qcomparehelper.h: simplify compareThreeWay() SFINAE helpersMarc Mutz2023-12-071-3/+6
| | | | | | | | | | | | | 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>
* Teach Qt::compareThreeWay() to support native float16 typesIvan Solovev2023-12-071-1/+19
| | | | | | | | | | 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>
* tst_QCompare: restore some test coverage to QPartialOrderingMarc Mutz2023-12-051-0/+22
| | | | | | | | | | | | | | | | | | | | | 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 4b6f757020382ed157bf6beb572549f05e881359. Change-Id: I1938d09f696ed8d58143dbacccb72cfd54ca12dd Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* tst_QCompareHelpers: extract Qt/std-mapping into public headerMarc Mutz2023-12-051-12/+2
| | | | | | | We'll need this elsehere, too. Change-Id: I91a35a23dd201f7867898cee5b4d6743883f71fc Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Implement helper Qt::compareThreeWay() function for built-in typesIvan Solovev2023-11-282-27/+265
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Implement compare helper macrosIvan Solovev2023-11-283-0/+501
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Make Qt::partial_ordering binary-compatible to std::partial_orderingMarc Mutz2023-11-271-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Rename Q*Ordering to Qt::*_orderingMarc Mutz2023-11-211-275/+386
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since we cannot re-use the pre-existing QPartialOrdering type due to binary-compatibility issues (it's not BC to std::partial_ordering), we're no longer bound to copy its API for consistency. So copy std::*_ordering type API for consistency instead, to ease porting for users that can already use C++20 and everyone else come Qt 7. This patch is another step in that direction, renaming classes and their memmbers to std-compatible names. QPartialOrdering cannot change, as it's pre-existing. So add a completely new type Qt::partial_ordering. Adding conversions from QPartialOrdering is left for a follow-up patch. As a drive-by, change `\c Less` to `\l Less` in the \class documentation blocks of the new classes. Amending c6fe64b17c87ec985f17389bf08eee46606862d4, which didn't have a ChangeLog: [ChangeLog][QtCore] Added Qt::{partial,weak,strong}_ordering as drop-in C++17 stand-ins for C++20's std::{partial,weak,strong}_ordering. Task-number: QTBUG-119108 Change-Id: Ib1296de6b708571a6abca8843ba36c114f6fd34f Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Q*Ordering: supply is_{lt,gt,n,}eqMarc Mutz2023-11-211-0/+109
| | | | | | | | | | | | | | | | | | | | | std::is_eq etc work fine on our Q*Ordering types when C++20 is available. But in C++17 mode, they're absent. Plug the hole by providing them for our own types as hidden friends, so that users can use unqualified calls to transparently support both std::*ordering and Q*Ordering types, just like with comparison to literal zero. For some reason, we running here into https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903, even though this wasn't seen in other commits of the chain that use comparisons to literal zero. Suppress the warning. Then at least is_eq etc provide a safe fall-back for compilers and users affected by this bogus warning. Fixes: QTBUG-119100 Change-Id: Ie8519c92363401a0c9c8efba6eb0b6e030a8e235 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* tst_qxp_is_virtual_base_of: disable all warnings for GCC < 10Marc Mutz2023-11-131-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The -Winaccessible-base switch was added for GCC 10. Older GCCs had no way to suppress the warnings, and the existing suppression of -Winaccessible-base caused a warning of its own: qcompilerdetection.h:1125:49: warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas] 1125 | #define QT_DO_PRAGMA(text) _Pragma(#text) | ^~~~~~~ qcompilerdetection.h:1150:49: note: in expansion of macro ‘QT_DO_PRAGMA’ 1150 | # define QT_WARNING_DISABLE_GCC(text) QT_DO_PRAGMA(GCC diagnostic ignored text) | ^~~~~~~~~~~~ tst_is_virtual_base_of.cpp:53:1: note: in expansion of macro ‘QT_WARNING_DISABLE_GCC’ 53 | QT_WARNING_DISABLE_GCC("-Winaccessible-base") | ^~~~~~~~~~~~~~~~~~~~~~ Since GCC 8 and 9 are slowly fading away as supported compilers, the simplest fix to get a clean build is to suppress all warnings for the test on these compilers, by passing -w, as suggested by https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90449. Short of moving the affected code into a separate header file and applying `#pragma GCC system_header` to it, there appears to be no other way to get rid of the warning. Amends a1bdee4697b7125bd0972284bfb33a56fcb441aa. Change-Id: I12eb1f8d486b1e2413675991659bf9ad3a7869ae Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
* is_virtual_base_of: suppress warnings in the testGiuseppe D'Angelo2023-09-281-0/+4
| | | | | | | | | We want to test the traits even on nonsensical types. Change-Id: I63ed022c9529d9de9d336157e6f025937321ca16 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Long live qxp::is_virtual_base_ofGiuseppe D'Angelo2023-09-263-0/+115
| | | | | | | | To be used in QWeakPointer. Change-Id: I5ee9dd0862a0b23d316aaadf5d68bef1ce609e8b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live Q_(U)INT128_C()!Marc Mutz2023-09-141-0/+129
| | | | | | | | | | | | | | | | | Compilers that support 128-bit integer types usually don't have support for 128-bit literals, so provide Q_(U)INT128_C macros and back them with UDLs. This, of course, only works in C++, so until compilers provide built-in literals that support C, too, that's all we get. [ChangeLog][QtCore] Added Q_INT128_C() and Q_UINT128_C() macros to create qint128 and quint128 literals in a platform-independent way. Pick-to: 6.6 6.6.0 Fixes: QTBUG-116822 Change-Id: I4be645baf2e007ee1aa1a27f9b5166671806dc49 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live Q_(U)INT128_MIN/MAX!Marc Mutz2023-09-132-0/+74
| | | | | | | | | | | | | Since compilers don't provide such macros, do it ourselves. In order to test these macros, add ad-hoc specializations of QTest::toString() for qint128 and quint128 locally to the test. Turns out it's not too hard to write them, so we might move them to a public header, yet. Pick-to: 6.6 Change-Id: I1483f3af2ccec6038e1c780649f9ffe413bb59ef Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add some tests for q(u)int128Marc Mutz2023-09-132-0/+13
| | | | | | | | | Check that QIntegerForSize<16> and std::numeric_limits<quint128> work and that q(u)int128 are available in C mode, too. Pick-to: 6.6 Change-Id: I44af8282399c78f6e74a8268af53bad64407ca34 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>