summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.h
Commit message (Collapse)AuthorAgeFilesLines
* QtWidgets: clean up API removalsMarc Mutz2021-07-271-0/+36
| | | | | | | | | | | As suggested by Peppe and Lars, use one file per module to hold the removed functions, not one per major version and subdir. Also, make the remove macro more like QT_DEPRECATED_SINCE. Change-Id: I2ade51ccc8cb8720ece493936775dfd3b5d438d7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* qSwap: make it constexprGiuseppe D'Angelo2021-07-071-1/+1
| | | | | | | | | | | C++20 gave us constexpr std::swap, but it makes no sense for qSwap not to be constexpr anyways. [ChangeLog][QtCore][QtGlobal] qSwap is now constexpr. Change-Id: I13f3cbf2870adf5770c62dc00e15004978fc85d9 Pick-to: 6.2 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Farewell Q_DISABLE_MOVEGiuseppe D'Angelo2021-05-261-5/+2
| | | | | | | | | | | | | | | | | | | | In hindsight, this macro is an API mistake, as it should NEVER be used alone, but always in combination with Q_DISABLE_COPY. But in that case, there's a better macro: Q_DISABLE_COPY_MOVE; hence this API is either bad, or completely redundant. A GitHub search reveals that luckily there's a handful of usages in the wild (of which 0 in Qt/dev and KDE). Hence, I'm going for the kill, and removing it entirely. [ChangeLog][Source-Incompatible Changes][QtGlobal] The Q_DISABLE_MOVE macro has been removed. Code that was using it can be ported to Q_DISABLE_COPY_MOVE instead. Change-Id: I7e346f7e2288f3f5a45315f4f6bfaeb2661f1de5 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix single argument QT_OVERLOADED_MACRO with pedantic warnings enabledTor Arne Vestbø2021-05-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The use of QT_OVERLOADED_MACRO combined with pedantic warnings would result in warning: must specify at least one argument for '...' parameter of variadic macro [-Wgnu-zero-variadic-macro-arguments] when used with a single argument, as the QT_VA_ARGS_COUNT macro would end up not passing anything to the last ... argument of the helper macro QT_VA_ARGS_CHOOSE. To work around this we extend the arguments passed to QT_VA_ARGS_CHOOSE by one, adding a zero-count, so that the variadic parameter always has at least one argument. Unfortunately this doesn't give us a count of 0 if a overloaded Qt macro is used without arguments, due to __VA_ARGS__ always being treated as an argument to QT_VA_ARGS_CHOOSE, even when empty, due to the comma after it. The result is that we end up calling the 1-argument macro for this case as well. Getting a correct zero-count, for both MSVC and GCC/Clang, without using GCC extensions, is quite involved, so we're opting to live with this limitation. See https://stackoverflow.com/a/62183700 for details. Fixes: QTBUG-93750 Pick-to: 6.1 Change-Id: Ib7b26216f36a639642a70387e0d73223633ba6b6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live qToUnderlyingGiuseppe D'Angelo2021-05-181-0/+7
| | | | | | | | | | | "Cherry-pick" of C++2b's std::to_underlying. [ChangeLog][QtCore][QtGlobal] The qToUnderlying function has been added, to convert an value of enumeration type to its underlying value. Change-Id: Ia46bd8e4496e55174171ac2f0799eacbcca02cf9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make qTerminate available when QT_NO_EXCEPTIONS flag is setAlexey Edelev2021-05-161-1/+1
| | | | | | | | | | | | It seems that QtCore could only be compiled with exceptions enabled. Therefore it doesn't make sense to keep conditonal code under QT_NO_EXCEPTIONS in qglobal.cpp. qTerminate may be called whether exceptions are enabled or not. Pick-to: 6.1 Fixes: QTBUG-93739 Change-Id: Ie49c10f27cfa75360f018e8638603e6a1791450e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QNativeInterface helpers to their own header fileTor Arne Vestbø2021-05-101-24/+0
| | | | | | | | | The machinery is not needed for all translation units, so keep it out of qglobal.h. Change-Id: Ib0459a3f7bc036f56b0810eb750d4641f567f1fe Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Tweak naming of QT_OVERLOADED_MACRO variantsTor Arne Vestbø2021-05-041-4/+4
| | | | | | | | Add a _ suffix before the number of arguments, to improve readability of the argument-specific functions. Change-Id: I1dfc4f381450825dd143ece524bb10e117c09971 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Long live PRI*QdatatypesGiuseppe D'Angelo2021-04-251-1/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Qt defines some integral datatypes (qsizetype, qintptr, quintptr, qptrdiff) not in terms of the corresponding language datatypes (resp. make_signed_t<size_t>, intptr_t, uintptr_t, ptrdiff_t) but as "integer types with the same bit size of the corresponding language type" (and of course the corret correct signedness for the target type). This makes the Qt datatypes not printable via printf-like formatted output, incl. qDebug, qWarning, QString::asprintf and so on; that's because there isn't a format modifier that would universally work with the Qt definitions. For instance, on a 32 bit platform, ptrdiff_t may be a typedef for long, while qptrdiff is a typedef for _int_ instead. Both long and int would indeed be 32 bits, but they still are different types, and this means that the ptrdiff_t-specific 't' length modifier would be wrong for qptrdiff: qptrdiff p; printf("%td", p); // WARNING: -Wformat: wanted long, got int Similarly, not using 't' breaks on 64 bits, and so on and so forth. There isn't a way out, short of inserting casts on every print statement. So, let's adopt the same solution C/C++ use for their own integer typedefs: the PRIx macros. This allows one to always use the correct formatting specifier without the need of a cast. I'm not adding the macros for the qintXX datatypes, as they already exist in the Standard Library. [ChangeLog][QtCore][QtGlobal] A series of PRIxQTDATATYPE macros have been added. They make it possible to print some Qt type aliases (qsizetype, qintptr, etc.) via a formatted output facility such as printf() or qDebug() without raising formatting warnings and without the need of a type cast. Change-Id: I473226a661868aed9514d793c8e6e4d391ab5055 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Fixed type integers: streamline the definitionsGiuseppe D'Angelo2021-04-241-7/+2
| | | | | | | | | | | | | | | | | | | | | | On all the platforms we support, we require these sizes in bits: * char: 8 * short: 16 * int: 32 * long long: 64 We can get rid of the MSVC-specific type aliases (MSVC guarantees __intXX to be aliases anyhow, not extended integer types) and just use the builtin types. Also, we require C++11 and C99, so "LL" and "ULL" are the correct standard suffixes for (unsigned) long long. Remove the non-standard suffixes from the Q_(U)INT64_C macros. Change-Id: If007cd88d74064a163b5e910ca1983acd1dd1d10 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>
* Add "QT_DEPRECATED_VERSION_XXX" macrosJiDe Zhang2021-04-121-0/+32
| | | | | | | | | Since 6.3 to 6.6, for which version add "QT_DEPRECATED_VERSION_X_6_" and "QT_DEPRECATED_VERSION_6_" macro. Change-Id: I10c77b1ed436ce3442960f5594f86a3a3be181f2 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Enforce __cplusplus >= 201703L on MSVCGiuseppe D'Angelo2021-03-221-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Client code on MSVC *must* pass /Zc:__cplusplus when using Qt. Otherwise, this makes Qt code that relies on feature-testing macros a mess. For instance, in QTBUG-91117, we trip on this code: // C++ version guard is necessary: you may have the header, // but including it in pre-C++20 will cause an hard error #if __has_include(<bit>) && __cplusplus > 201703L #include <bit> #endif #if defined(__cpp_lib_bitops) // use some <bit> functionality #endif The #define __cpp_lib_bitops should've come from the preceding include directive, but there's another possibility: that it comes from <version> (or some other similar header) included transitively, when compiling in C++20 mode, and *without* a bumped __cplusplus. Yes, that's an actual possibility on MSVC. Then, since we did not include <bit> ourselves due to the __cplusplus version check, using the functionality will cause a compile error. We're not going to fix *every* post C++-17 feature detection macro because of MSVC and feature-test shenanigans. It's time to require compilers to tell us the truth about what they support. Fixes: QTBUG-91117 Change-Id: I9d74f9d8b74b5ac35dce3528e7a2006746a00676 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Add the 6.2 deprecation macrosGiuseppe D'Angelo2021-03-021-0/+8
| | | | | | | | | ... which makes me wonder, why isn't this stuff bumped automatically when a minor version branch is created? Change-Id: Ia43f898163a4baa0896a09bd13d65cf534fe1df5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Mark qBadAlloc as [[noreturn]]Giuseppe D'Angelo2021-01-191-1/+1
| | | | | | | | | | | | So that static analyzers don't get confused by its semantics. In builds with exceptions disabled, it's not actually called by client code (e.g. Q_CHECK_PTR will just terminate in that case), but we still need to make it not return -- add another path that callss std::terminate(), otherwise we'd have a noreturn function returning. Change-Id: Ia8c4ce3e9d971f1757e9c273051cb3dedf23c61f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add deprecation warnings for 6.1Giuseppe D'Angelo2020-11-201-0/+8
| | | | | Change-Id: I8e78f29f338670078488247f233b99125eabb4b6 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Optimize qRoundAllan Sandfeld Jensen2020-11-161-0/+24
| | | | | | | | | These variants produce the same code as if std::round was compiled with -ffast-math. Change-Id: I8e0d7601928a511b9bc8b8f969cfd94df47c3784 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* qglobal: Only define QT_ENSURE_STACK_ALIGNED_FOR_SSE for i386Martin Storsjö2020-11-041-1/+1
| | | | | | | | | | This define is only supposed to be used for i386, but was set for any 32 bit mingw architecture (which also covers armv7). Change-Id: Iedc057dfc493015e8339db837dbe20a57c2b2367 Pick-to: 5.15 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Do not #define dynamic_castGiuseppe D'Angelo2020-11-021-13/+0
| | | | | | | | | | | | | It's illegal. [macro.names]/2: "A translation unit shall not #define or #undef names lexically identical to keywords" If someone tries to use dynamic_cast in a no-rtti scenario, let's just have the compiler yell at them for that. Change-Id: I70a7b55a93d34c433e874d379acae8b256620f80 Pick-to: 5.15 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Resolve corelib's remaining ### Qt 6 commentsEdward Welbourne2020-11-021-1/+1
| | | | | | | | | | | | | No action taken at Qt 6, suggesting it shall never happen. Four removed, one converted to Qt 7, others converted to unversioned TODOs. Filed Jira tasks, and referenced in comments, for those retained. There remain two "once bootstrap builds are obsolete" comments and one other on which pending action may yet happen. Fixes: QTBUG-85700 Change-Id: Ib140a6a21c63370e51e4734cc591f67573a29d9a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Warn if Q_FOREACH is used with a non-shared containerOlivier Goffart2020-11-021-0/+14
| | | | | | | | Show a deprecation warning if a non shared container is used within Q_FOREACH, because it would make an expensive copy of the container Change-Id: I70cfd789b5b8d9f5b1bd6e0a57e5e968e1c6a0ca Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Whitespace cleanup in corelib/globalAllan Sandfeld Jensen2020-10-211-2/+2
| | | | | Change-Id: I087d7d949cfd43e48e8a008621a4eeaa9d104ceb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add noexcept to d-ptr accessor functionsAllan Sandfeld Jensen2020-10-191-8/+9
| | | | | | | | | | In theory this could be source incompatible with Q_DECLARE_PRIVATE on a QSharedDataPointer, but that would both be a misuse, and all places where something like that could have been used in Qt, Q_DECLARE_PRIVATE is already manually inlined. Change-Id: I60bdde3a71646129cef84f31624d0432e7af91ab Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* doc: Update and flesh out native interface docsTor Arne Vestbø2020-10-181-2/+2
| | | | | | | | | The namespace and overviews are in the qtdoc repository. Docs for individual interfaces should live with their platform. Change-Id: Iba5fd7e9ebc4f1f634ec9dc3ec125ce88a1312ba Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Disallow promotion of bool and char in qMin and friendsLars Knoll2020-10-161-1/+3
| | | | | | | | | Feedback on the API review. Make sure, qMin<true, 'a'> and similar constructs don't compile. Change-Id: I59a66348a4168fe306159ddaf2595838d4ed66d1 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QOverload helpers: further cleanupsGiuseppe D'Angelo2020-10-161-3/+3
| | | | | | | constexpr inline means we can remove [[maybe_unused]]. Change-Id: I034b6e742ef750dc1ebeca1d9cc7a2463f8c7b70 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Floating point function helpers: code tidiesGiuseppe D'Angelo2020-10-161-6/+6
| | | | | Change-Id: Id87390734f4ccb28fb83d25788ca600747c2e2a8 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QtPrivate::Deprecated_t: code tidiesGiuseppe D'Angelo2020-10-161-1/+1
| | | | | Change-Id: I08ae749b32aa9a302937691c76b7910175c8a71a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QOverload helpers: code tidiesGiuseppe D'Angelo2020-10-151-10/+4
| | | | | | | | | Remove pre-C++14 code paths; and mark as `inline` the qOverload helper objects (constexpr variables at namespace scope aren't automatically inline). Change-Id: Ieb2a9f06e39720d0c7215a3d1273c3a5996d0bc7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Long live Q_IMPLICIT!Giuseppe D'Angelo2020-10-141-0/+6
| | | | | | | | | | | | | C++20 will give us explicit(bool). While we can't use it just yet in its full potential, we can introduce a macro to start marking our implicit conversions (aka `explicit(false)`), removing the need for /* implicit */-like comments. Port a few usages to it. Change-Id: I336d5e4c8d51d8329627900d1059e59062c5cafd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Drop qt_is_permutationGiuseppe D'Angelo2020-10-141-23/+0
| | | | | | | | | | It was a workaround until we could depend on C++14's std::is_permutation overload with 4 args. We now can, and the code using it is gone anyhow, so drop it. Change-Id: Ib9af71eeb767c83b1150c482441503288f1987d4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Another round of replacing 0 with nullptrAllan Sandfeld Jensen2020-10-071-1/+1
| | | | | | | | | This time based on grepping to also include documentation, tests and examples previously missed by the automatic tool. Change-Id: Ied1703f4bcc470fbc275f759ed5b7c588a5c4e9f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Rename the new platform APIs from QPlatformInterface to QNativeInterfaceTor Arne Vestbø2020-10-071-8/+13
| | | | | | | | | | | | We were already using the 'native' nomenclature when referring to these kinds of APIs, e.g. when talking about native handles, or the existing QPlatformNativeInterface on a QPA level. Using 'native' for the user facing APIs also distinguishes them from the 'platform' backend layer in QPA and elsewhere. Change-Id: I0f3273265904f0f19c0b6d62471f8820d3c3232e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Replace Q_DECL_UNUSED with [[maybe_unused]]Allan Sandfeld Jensen2020-10-031-10/+10
| | | | | | | Use C++17 attribute directly Change-Id: Id853e7a5117065e4adb549f81303c1820fe198ce Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Centralize the implementation of move assignment operatorsGiuseppe D'Angelo2020-10-031-0/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Switch Q_DECL_DEPRECATED to use C++14 [[deprecated]]Allan Sandfeld Jensen2020-10-031-1/+1
| | | | | | | | | | As a C++ attribute it must be on the beginning of the line or after the function name however. And for friend declarations can only be on the definition. Change-Id: I456884428f36e1f1c621089c7b1addee13ada0fe Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace Q_REQUIRED_RESULT with [[nodiscard]]Allan Sandfeld Jensen2020-09-251-6/+6
| | | | | | | It was already used many places directly making the code inconsistent. Change-Id: I3b14bc6c333640fb3ba33c71eba97e78c973e44b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Normalize roundingAllan Sandfeld Jensen2020-09-161-4/+4
| | | | | | | | Change the rounding of negative half values to match standard C++ round, this will also allow future optimizations. Change-Id: I8f8c71bed1f05891e82ea787c6bc284297de9c5c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clean up the last of QT6_(NOT_)?VIRTUALEdward Welbourne2020-09-141-5/+1
| | | | | | | | | This follows up on commit d273076b4474bb473d90e996960c4c773745761a which left a comment asking for the clean-up this finishes. Task-number: QTBUG-85700 Change-Id: I1c6896a42a09b873302ad7ec8273879f2a4a4ce6 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Get rid of QEnableIfLars Knoll2020-09-111-6/+0
| | | | | | | Use std::enable_if instead. Change-Id: I02a2f3066f9e4cab6db1909681a17330afdbbedb Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Remove pre-C++17 code pathLars Knoll2020-09-111-17/+0
| | | | | Change-Id: Iaa7f677f45cee50f0b9ed236cf5bef18d5764bfa Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Use C++17 [[maybe_unused]]Allan Sandfeld Jensen2020-09-061-10/+10
| | | | | | | In some places needs to be ordered before const/constexpr though. Change-Id: I57a521ac0ad22b5a018761c4d52befbef69d64c0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Purge qalgorithm.h of deprecated APIEdward Welbourne2020-08-281-0/+1
| | | | | | | | | | | | | A large slice of it has been deprecated since 5.2. Reflowed a doc paragraph pointed out, in the deprecation commit, as having been left ragged by its edits. Note: qSwap() is documented as \deprecated but not marked, where it's defined, as deprecated. Change-Id: Iaff10ac0c4c38e5b85f10eca4eedeab861f09959 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Follow through on ### Qt6 comments in qglobal.hEdward Welbourne2020-08-181-20/+0
| | | | | | | | | | Left the translation NOOP for later, pending advice on how to fix QIODevice, which doesn't compile without them. Task-number: QTBUG-85700 Change-Id: Icc423ecabb43714d98b5d9b0f9a96c5bb6ef1d78 Reviewed-by: Martin Storsjö <martin@martin.st> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Replace Qt CONSTEXPR defines with constexprAllan Sandfeld Jensen2020-08-141-22/+22
| | | | | | | | Both normal and relaxed constexpr are required by our new minimum of C++17. Change-Id: Ic028b88a2e7a6cb7d5925f3133b9d54859a81744 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* qglobal.h: remove deprecated global functionsEdward Welbourne2020-08-141-15/+0
| | | | | | | | Since 5.0 - qMalloc(), qFree(), qRealloc(), qMemCopy(), qMemSet() Since 5.15 - qsrand(), qrand() Change-Id: I74fa3d17b05521271c3dc563fc85a5b133289ce3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Avoid UB in moc generated codeLars Knoll2020-08-071-0/+11
| | | | | | | | | | | | | | Introduce a Q_OFFSETOF() macro that uses the optional support of offsetof() for non standard layout types and disables the corresponding compiler warnings. All our supported compilers support offsetof() on non standard layout types. Use the macro to do the offset calculations required in moc generated code to replace a manual offset calculation that was dereferencing a null pointer. Change-Id: I4aab3af3c8bbaa90372f2234aa1cf8399d023c22 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Introduce QByteArrayViewSona Kurazyan2020-07-081-2/+0
| | | | | | | | | | | | | | | | | | | | Created a QByteArrayView in symmetry with QStringView. Added the basic tests symmetrical to QStringView tests. Moved the implementations of non-modifying methods of QByteArray to namespace QtPrivate, to be reused inline from both QByteArray and QByteArrayView. Changed QByteArray's counterparts of those methods to take QByteArrayView as argument instead of QByteArray. Removed QByteArray's operator QNoImplicitBoolCast(), because it was causing ambiguity when calling those methods with QByteArray argument (it was there to perevnt if(!ba)/if(ba) from compiling, but currently that would be ambiguous and won't compile anyway). [ChangeLog][QtCore][QByteArrayView] New class. Task-number: QTBUG-84321 Change-Id: I05f92e654cf65c95f2bb31b9c9018746ac110426 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Clarify warning message about PIC/PIEDaniel Kahn Gillmor2020-07-071-1/+1
| | | | | | | | | | | | As noted in discussion at https://dev.gnupg.org/T4982#135524, when there is a mismatch between position-independence of the Qt library and other compilations, the warning produced by Qt is confusing. It should say explicitly that -fPIE should not be passed. Change-Id: I66394f86230a6598ac383bfd7bb14ab8cbbf6245 Pick-to: 5.15 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Introduce platform API abstraction for QOpenGLContextTor Arne Vestbø2020-07-021-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The API is available by including qopenglcontext.h as usual, but scoped in the QPlatformInterface namespace. The namespace exposes platform specific type-safe interfaces that provide: a) Factory functions for adopting native contexts, e.g. QCocoaGLContext::fromNative(nsContext, shareContext); b) Access to underlying native handles, e.g. openGLContext->platformInterface<QCocoaGLContext>->nativeContext() c) Platform specific functionality, e.g. static QWGLContext::openGLModuleHandle() openGLContext->platformInterface<QEGLContext>->doSomething(); The platform interfaces live close to the classes they extend, removing the need for complex indirection and plumbing, and avoids kitchen-sink modules and APIs such as the extras modules, QPlatformFunctions, or QPlatformNativeInterface. In the case of QOpenGLContext these platform APIs are backed by the platform plugin, so dynamic_cast is used to ensure the platform plugin supports the requested interface, but this is and implementation detail. The interface APIs are agnostic to where the implementation lives, while still being available to the user as part of the APIs they extend/augment. The documentation will be restored when the dust settles. Task-number: QTBUG-80233 Change-Id: Iac612403383991c4b24064332542a6e4bcbb3293 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Allow qMin, qMax and qBound for types that can be losslessly convertedLars Knoll2020-06-251-0/+43
| | | | | | | | | | | | | | | | Add overloads for qMin and friends where the arguments are of different type, but one can be easily promoted to the other. Return the promoted type. Promotions are only allowed if both types are either signed, unsigned or floating point numbers. This should simplify writing code in many case (as for example qMin(myint64, 1)) and also help reduce source incompatibilities between Qt 5 and Qt 6, where the return types for sizes of our containers changes from int to qsizetype. Change-Id: Ia6bcf16bef0469ea568063e7c32f532da610d1cd Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>