summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
Commit message (Collapse)AuthorAgeFilesLines
* QBindable: Make ordinary Q_PROPERTYs bindablePatrick Stewart2022-11-306-0/+301
| | | | | | | | | | | Implements an adaptor from the notification signal of a Q_PROPERTY to QBindable. The Q_PROPERTY does not need to be BINDABLE, but can still be bound or used in a binding. [ChangeLog][Core][Q_PROPERTY] Q_PROPERTYs without BINDABLE can be wrapped in QBindable to make them usable in bindings Change-Id: Id0ca5444b93a371ba8720a38f3607925d393d98a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qfloat16: make it a built-in metatypeThiago Macieira2022-11-283-5/+15
| | | | | | | | | | | I've reserved the IDs for int128, uint128, bfloat16, and float128, because the mask in qvariant.cpp's qIsNumericType() requires primitives to be less than 64 to operate properly. Added a QMetaType/QDataStream test to confirm it is indeed built-in. Change-Id: I3d74c753055744deb8acfffd17247f7f57bada02 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* qfloat16: add support for native _Float16 (C2x extended floating point)Thiago Macieira2022-11-281-2/+2
| | | | | | | | | | | | | | | | | | | | The C++ equivalent is std::float16_t, defined in P1467[1], and is coming with GCC 13 both in native mode (for x86, using AVX512FP16) and in emulated mode. The C and C++ types will be the same type (<stdfloat> simply typedefs). qfloat16 will need to remain a wrapper with an integer member to keep ABI with previous Qt versions. Because it is a trivially-copyable small type, it gets currently passed in registers; the presence of the integer member means it gets passed in general-purpose registers, while a single _Float16 member would be passed in a floating-point register. See: https://gcc.godbolt.org/z/8fEendjff [1] https://wg21.link/p1467 Change-Id: I8a5b6425b64a4e319b94fffd161be56397cb48e6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* QObject: stronger warning about isSignalConnected and threadsVolker Hilsheimer2022-11-261-13/+20
| | | | | | | | | | | | | | Document explicitly that it is not allowed to call isSignalConnected from (dis)connectNotify overrides, and add the respective warning from the disconnectNotify documentation also to the connectNotify documentation (with some light editing). Pick-to: 6.4 6.2 Fixes: QTBUG-106025 Change-Id: I41e8a9d3e6ce697cb2943d55a7c853eeec9c1dbe Reviewed-by: Lars Knoll <lars@knoll.priv.no> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix typo in documentation for QVariant::nameToTypeNicolas Fella2022-11-251-1/+1
| | | | | | | | Pick-to: 6.4 6.2 Change-Id: I69742b9e597012329de5f5f742d4972ea7575775 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add permission backend for WASMTor Arne Vestbø2022-11-241-0/+278
| | | | | | | | | | | The only permissions we support so far are camera, microphone, and location. The permission API works even for browsers that don't provide the Web Permission API, as we plumb the individual permission requests for media and geolocation back to our API. Change-Id: I7f5fc2266afee9ada78f2015614a8224e28afa59 Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Reintroduce converter APIs for supporting native clipboard formatsVolker Hilsheimer2022-11-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Qt 5, QWin(dows)Mime and QMacMime lived in the respective Extras modules, which were removed and partially folded into the relevant modules in Qt. QWindowsMime and QMacMime continued to provide the abstraction for implementing built-in support for native clipboard formats and UTIs within Qt, but only as private APIs. After the recent clean up of those APIs and respective infrastructure, we can now bring them back as public converter interfaces. Application developers can subclass those and instantiate an instance of their implementation to add support for platform or application specific data formats. These interfaces are not in the QNativeInterface namespace, as applications don't call into Windows or macOS using those interfaces. I.e. there is no class on which an application would call auto *converter= nativeInterface<QWindowsMimeConverter>(); Also, since applications override those converter types, we do want to guarantee binary and source compatibility. [ChangeLog][QtGui][QWindowsMimeConverter] Reintroduced to allow applications to add support for conversion from and to Windows-native clipboard formats to MIME-encoded data. [ChangeLog][QtGui][QUtiMimeConverter] Reintroduced to allow applications to add support for conversion from and to clipboard data on macOS and iOS to MIME-encoded data. Fixes: QTBUG-93632 Change-Id: Iebd909c3970015d203f59d5ab15e306b3d312f6e Reviewed-by: Yuhang Zhao <2546789017@qq.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Windows: centralize how we handle error messagesYuhang Zhao2022-11-162-1/+13
| | | | | | | | | | | | | | | | Currently QtBase contains multiple implementation of how to get the Win32 and COM error messages, and they are almost exactly the same, what's worse, Qt already has a private QSystemError class to do such things, so we are re-inventing the wheel in many places. This patch removes all other custom error message implementations besides the QSystemError one. And since there are a lot of places need the COM error message, move the implementation to QSystemError so that it can handle both Win32 error and COM error. Since I'm touching these lines anyway, break them into short lines if they are above the length limit. Change-Id: I1067c874011800303f0f114b5cb8830ac6810fc0 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QTimerInfo/Unix: use chrono for time arithmeticAhmad Samir2022-11-111-5/+9
| | | | | Change-Id: I2e193e2293c15e722d2e5c32ac8f7db1b5b7514a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Plumb public permission APIs to Android backendTor Arne Vestbø2022-11-092-0/+170
| | | | | | | | | | | | | | | | | | | | | | | | The lock and unlock of the Android deadlock mutex is now part of the internal implementation instead of limited to the enum based permission API. It is unclear why 8bca441b6f65 added the guard only to this API and not to the string based API as well. The check for isBackgroundLocationApi29 has been removed, as the logic seemingly resulted in accepting every single permission type except location permissions if used via the enum-based API. Since Android's platform permission API doesn't have an Undetermined status, we keep a hash of the status for each permission type, and by default checkPermission() would return Undetermined, until a requestPermission() call is done which updates the internal hash, and after that checkPermission() would return properly Granted/Denied. Task-number: QTBUG-100413 Change-Id: Ia95c76af754481a281bc90198e349966c9c2da52 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QVariant: add support for numeric comparisons for char16_t and char32_tThiago Macieira2022-11-091-1/+7
| | | | | Change-Id: I3d74c753055744deb8acfffd17248af45fd20556 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant: fix comparison of enums to numericsThiago Macieira2022-11-091-4/+38
| | | | | | | | | | qIsNumericType does not return true for enum types, which meant we never called numericCompare() or numericEquals() when one of the types was an enum. Task-number: QTBUG-108188 Change-Id: I3d74c753055744deb8acfffd172449c68af19367 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant: simplify getting integer contents by using the type sizeThiago Macieira2022-11-091-40/+31
| | | | | | | | | | | This reduces the chances of mistakes in forgetting a type. Plus, this makes it easier to add char16_t and char32_t. Drive-by change some type().id() code that doesn't need the ID for user types to typeInterface()->typeId. Change-Id: I3d74c753055744deb8acfffd17248aa81bf8ce55 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant: move the NaN comparison into the spaceShip functionThiago Macieira2022-11-091-2/+4
| | | | | | | Note: NaN = not Not A Naan Change-Id: I3d74c753055744deb8acfffd17248a02f7968121 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant: use QPartialOrdering for the internal comparison functionsThiago Macieira2022-11-091-33/+16
| | | | | | | | | | | | Avoids having to have a convertOptionalToPartialOrdering() function to convert back. std::optional<int> is 64 bits on any platform, though it's returned in registers for the IA-64 C++ ABI. Unfortunately, that's not the case for Windows. Change-Id: I3d74c753055744deb8acfffd172480eee189b3b2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant: merge the equality and ordering compare functionsThiago Macieira2022-11-091-36/+2
| | | | | | | | | | As we're not doing any deep analysis, the code is almost exactly the same anyway. It is possible to simplify further by avoiding the signed/unsigned conversion rules, but it's not worth the effort. Instead, we can share code. Change-Id: I3d74c753055744deb8acfffd17248a5c51cbbfcb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant: make a major simplification in the numeric comparisonThiago Macieira2022-11-091-49/+30
| | | | | | | | | | | | | | The code implementing the C++ rules of type promotion and conversion was too pedantic. There's no need to follow the letter of the standard, not when we can now assume that everything is two's complement (this was true for all architectures we supported when I wrote this code in 2014, but wasn't required by the standard). So we can reduce this to fewer comparisons and fewer rules, using the size of the type, not just the type ID. Change-Id: I3d74c753055744deb8acfffd172446b02444c0c0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant: get rid of output argument to qConvertTo{Real,}NumberThiago Macieira2022-11-091-63/+41
| | | | | Change-Id: I3d74c753055744deb8acfffd1724476a2e0e5a49 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Update the poll-exit-on-error code: include the message for everyoneThiago Macieira2022-11-081-5/+3
| | | | | | | | I think it's useful for everyone to know what error it was, not just if it's about to abort. And then simply abort() when we want to. Change-Id: I3d74c753055744deb8acfffd1724c5b2b293ca9a Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Update the poll-exit-on-error feature to be privateThiago Macieira2022-11-081-1/+1
| | | | | | | | | | User code shouldn't have to know about this. Amends 0e1ce757d530c5e84d4c3ad070fd8ebf47c2e3d2. Change-Id: I3d74c753055744deb8acfffd1724c5282f60ea59 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Dominik Holland <dominik.holland@qt.io>
* Rename QMacInternalPasteboardMime to QMacMimeVolker Hilsheimer2022-11-071-1/+1
| | | | | | | | | | | | | | | We want to make it public, and there is no need for "pasteboard" since it also coveres drag'n'drop. Add a default constructor that defaults to supporting both clipboard and drag'n'drop, and clean up the code by using that constructor where applicable. Historical note: the converter interface was called QMacMime up to Qt 4.2, when due to macOS changes it had to be replaced by QMacPasteboardMime. Task-number: QTBUG-93632 Change-Id: Id9712300039375aa6394598b104827e6f5d6c948 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* QEventDispatcherUNIX: remove unused includeThiago Macieira2022-11-051-1/+0
| | | | | | | Helpful hint from Qt Creator. Change-Id: I3d74c753055744deb8acfffd1724c53a97bd6132 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QMetaType: Document the default ctorMårten Nordheim2022-11-051-0/+7
| | | | | | | | | | It wasn't showing up in documentation. Amends 33cd680ddbaccf6139e215d851a39e657ae36394. Pick-to: 6.4 6.2 Change-Id: Ifb5d38fd3d4eb2ecd109ce53809fae5382916dff Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Add permission API backend for macOS and iOSTimur Pocheptsov2022-11-033-2/+134
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When submitting applications to the iOS and macOS AppStore the application goes through static analysis, which will trigger on uses of various privacy protected APIs, unless the application has a corresponding usage description for the permission in the Info.plist file. This applies even if the application never requests the given permission, but just links to a Qt library that has the offending symbols or library dependencies. To ensure that the application does not have to add usage descriptions to their Info.plist for permissions they never plan to use we split up the various permission implementations into small static libraries that register with the Qt plugin mechanism as permission backends. We can then inspect the application's Info.plist at configure time and only add the relevant static permission libraries. Furthermore, since some permissions can be checked without any usage description, we allow the implementation to be split up into two separate translation units. By putting the request in its own translation unit we can selectively include it during linking by telling the linker to look for a special symbol. This is useful for libraries such as Qt Multimedia who would like to check the current permission status, but without needing to request any permission of its own. Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Change-Id: Ic2a43e1a0c45a91df6101020639f473ffd9454cc Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-034-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to handle typedefs and accesses through pointers, too: const std::string o = "object"; auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); }; auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef<StringRef> classes, StringRef from, StringRef to) { return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)), callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))), changeTo(cat(access(o, cat(to)), "()")), cat("use '", to, "' instead of '", from, "'")); }; renameMethod(<classes>, "count", "size"); renameMethod(<classes>, "length", "size"); except that the on() matcher has been replaced by one that doesn't ignoreParens(). a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'. Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache, to avoid porting calls that explicitly test count(). Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Long live QPermissions!Tor Arne Vestbø2022-11-015-0/+885
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Many features of today's devices and operating systems can have significant privacy, security, and performance implications if misused. It's therefore increasingly common for platforms to require explicit consent from the user before accessing these features. The Qt permission APIs allow the application to check or request permission for such features in a cross platform manner. The check is always synchronous, and can be used in both library and application code, from any thread. The request is asynchronous, and should be initiated from application code on the main thread. The result of the request can be delivered to lambdas, standalone functions, or regular member functions such as slots, with an optional context parameter to manage the lifetime of the request. Individual permissions are distinct types, not enum values, and can be added and extended at a later point. Task-number: QTBUG-90498 Done-with: Timur Pocheptsov <timur.pocheptsov@qt.io> Done-with: Volker Hilsheimer <volker.hilsheimer@qt.io> Done-with: Mårten Nordheim <marten.nordheim@qt.io> Change-Id: I821380bbe56bbc0178cb43e6cabbc99fdbd1235e Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* QProperty: only use MSVC bug workaround on MSVCFabian Kosmale2022-10-311-1/+10
| | | | | | | | | | | | The fix for QTBUG-106277 appears to cause issues with older gcc versions in C++2a mode (for instance used in our headers check). Thus, use the old code for all non-MSVC compilers, which never had problems with it. Pick-to: 6.4 6.2 Fixes: QTBUG-108039 Change-Id: If6a0ce6e8f41e9dc752614557e96c555ca0fe75c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QWinRegistryKey: Fix how we handle the default value, take 2Yuhang Zhao2022-10-281-4/+5
| | | | | | | | | | | | It seems the value name correction is not needed at all, and we must not do such correction. Amends commit 738e05a55a4047268553eea6b9f4809d42181eef Task-number: QTBUG-107794 Change-Id: I903a762aafab4b55275beb8438e6769285821567 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
* Use consteval in QT_PROPERTY_DEFAULT_BINDING_LOCATIONPatrick Stewart2022-10-251-1/+7
| | | | | | | | | | | | | | | Adds a consteval QPropertyBindingSourceLocation::fromStdSourceLocation to make sure the QPropertyBindingSourceLocation is created at compile time. This is a workaround for what seem to be bugs in MSVC 2019 and 2022, which otherwise don't regard QPropertyBindingSourceLocation(std::source_location::current()) as a constant expression. Fixes: QTBUG-106277 Pick-to: 6.4 6.2 Change-Id: Ic2379987b278cc0c43c1eb929120c99f5cd95fdf Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QProperty: Update documentation to reflect eager evaluationFabian Kosmale2022-10-251-159/+182
| | | | | | | | | Amends cf42a0fe5e525efa9a399694cc6882c6e811c286. As a drive-by, reflow the documentation, and mark some code segments with \c Change-Id: Id644e841f9990dd7aec2d7ce74efad8b4472b93a Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Emit aboutToQuit from QCoreApplication::exit() instead of execCleanup()Tor Arne Vestbø2022-10-231-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The aboutToQuit signal is documented to be emitted "when the application is about to quit the main event loop", which is useful "if your application has to do some last-second cleanup", and is recommended over "putting it in your application's main() function because on some platforms the exec() call may not return". However, if we're on a platform where the exec call may not return, it will be because the event dispatcher's exec doesn't return, which means we'll never get out of the call to eventLoop.exec(QEventLoop::ApplicationExec) and into the execCleanup() code. In addition, on macOS, where we do currently return to main(), we do so by telling the platform to cancel the application termination, by returning NSTerminateCancel from applicationShouldTerminate, after running the quit logic of Qt via QWindowSystemInterface::handleApplicationTermination(). In the case of quitting applications due to system logout/shutdown, this cancellation brings up a dialog saying the Qt application interrupted the process, which luckily disappears again as soon as the application actually terminates via main(). Moving the emit of aboutToQuit() earlier in the flow, before we've cancelled the application termination, reduces the chance that long running code triggered from this signal will keep the dialog visible to the user. Task-number: QTBUG-102321 Change-Id: I362737e9563069fc02b1e9639e1251d655d13949 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Replace usages of Q_CLANG_QDOC with Q_QDOCLuca Di Sera2022-10-2111-38/+38
| | | | | | | | | | | | | | | | | | | | | | | 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>
* QWinRegistryKey: fix assert when querying default valueYuhang Zhao2022-10-211-2/+3
| | | | | | | | | | | | | | | | | I wrongly assumed we can't query a value with an empty name "" during the previous refactor commit, however, in Windows registry, an empty name for a value means the default value of a key, we can read and write it through the "Default" name. Remove the wrong assert to fix the crash when we are trying to query a default value of a key. Add a new test case to test this kind of scenarios. Amends commit 40523b68c14bf618bdc2d5438deebf34627be3af Fixes: QTBUG-107794 Change-Id: Idacbcb86df4435a8c1ca1c19121599390ae8f3d3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Make qt_mac_ensureResponsible QT_BUILD_INTERNAL and Q_AUTOTEST_EXPORTTor Arne Vestbø2022-10-192-1/+7
| | | | | | | | | | Its primary purpose was to be used by permission auto tests, so to avoid App Store compatibility issues we disable it in non-dev builds. Task-number: QTBUG-107167 Change-Id: Iaacec807808cfe52df0cf850b287e50da1bd59e5 Reviewed-by: Doris Verria <doris.verria@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Add the toDOMRect/fromDOMRect functions to QRectFMikolaj Boc2022-10-191-0/+45
| | | | | | | | These are very helpful when converting to and from DOMRect. Change-Id: I4a7fc6318f45bed8e2b82fd5d6ec174dc1762326 Fixes: QTBUG-107740 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* QApplicationStatic: avoid use of std::aligned_unionMarc Mutz2022-10-171-1/+1
| | | | | | | | | | | It's deprecated in C++23. Replace with std::aligned_union's implementation, like done elsewhere in the code base. Pick-to: 6.4 Fixes: QTBUG-107569 Fixes: QTBUG-99122 Change-Id: I0c06876c03a3c268298fab0f0bae399f26449bed Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Revert "QObject: attempt to fix a deadlock introduced by an earlier fix"Mårten Nordheim2022-10-171-11/+1
| | | | | | | | | | | | This reverts commit 22d4c67234fd152296c3ec98fc57526356a9f62b. Reason for revert: The fix causes crashes tst_QObjectRace::disconnectRace2 and we don't currently have a clear resolution on further fixes. Task-number: QTBUG-107034 Change-Id: I310c27654f125cdb2939940d432724e73c89f485 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: explicitly include qobject.hAlexey Rochev2022-10-161-0/+1
| | | | | | | | | | | | convertMetaObject() function requires definition of QObject class, but qobject.h is not included explicitly. Instead it is pulled by qabstractitemmodel.h. Include it explicitly to fix builds with -no-feature-itemmodel. Pick-to: 6.4 6.2 Change-Id: I4386375588c451262923501ab8dd7374c1f729ec Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Long live Q_UNREACHABLE_RETURN()!Marc Mutz2022-10-153-8/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a combination of Q_UNREACHABLE() with a return statement. ATM, the return statement is unconditionally included. If we notice that some compilers warn about return after __builtin_unreachable(), then we can map Q_UNREACHABLE_RETURN(...) to Q_UNREACHABLE() without having to touch all the code that uses explicit Q_UNREACHABLE() + return. The fact that Boost has BOOST_UNREACHABLE_RETURN() indicates that there are compilers that complain about a lack of return after Q_UNREACHABLE (we know that MSVC, ICC, and GHS are among them), as well as compilers that complained about a return being present (Coverity). Take this opportunity to properly adapt to Coverity, by leaving out the return statement on this compiler. Apply the macro around the code base, using a clang-tidy transformer rule: const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule( stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)) ); where nextStmt() is copied from some upstream clang-tidy check's private implementation and subStmt() is a private matcher that gives access to SwitchCase's SubStmt. A.k.a. qt-use-unreachable-return. There were some false positives, suppressed them with NOLINTNEXTLINE. They're not really false positiives, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. I haven't figured out how to remove the empty line left by the deletion of the return statement, if it, indeed, was on a separate line, so post-processed the patch to remove all the lines matching ^\+ *$ from the diff: git commit -am meep git reset --hard HEAD^ git diff HEAD..HEAD@{1} | sed '/^\+ *$/d' | recountdiff - | patch -p1 [ChangeLog][QtCore][QtAssert] Added Q_UNREACHABLE_RETURN() macro. Change-Id: I9782939f16091c964f25b7826e1c0dbd13a71305 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-117-9/+9
| | | | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QVariant/Doc: expand what toList & toMap conversions may succeedThiago Macieira2022-10-111-5/+14
| | | | | | | | | | | | | I don't know when conversion through sequential and associative iteratables was added, probably some time in the 5.x. QString and QByteArray got conversions to sequential iteratables for Qt 6.1 with commit c9a11022692f9a4bd36beb0cd001686694a48915. Since that was intentional, I'm just documenting reality. Fixes: QTBUG-107246 Pick-to: 6.2 6.3 6.4 Change-Id: Id8d5e3999fe94b03acc1fffd171b863b1a0ead68 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QSharedMemory/doc: update docs to be more modernThiago Macieira2022-10-111-17/+95
| | | | | | | | | | | | | - We don't support HPUX any more, so no need to talk about it - Clarify that it's the QSharedMemory destructor that releases the resources on Unix systems - Explain the System V and POSIX backends and how to detect them - Add a note about Android not being supported. - Add a section about using QFile for shared memory Change-Id: I413ea647c2a5453b8307fffd17174c8083416529 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Add a configure option to exit on poll errorsDominik Holland2022-10-111-0/+4
| | | | | | | | | | | | | | If an error is returned from qt_safe_poll inside the event dispatcher the error is currently printed and ignored. For most cases this behavior seems to be fine, but when used in critical systems e.g. automotive or medical, a error might indicate a more severe problem and the application should be stopped instead. The system can then decide itself what to do e.g. restarting the application using a watchdog. Change-Id: Iaf5abb20bb3941eaeff19d14e41c395c88fa088d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSystemSemaphore: make it a Q_GADGETThiago Macieira2022-10-102-0/+4
| | | | | | | | So we can have Q_ENUM. Change-Id: If4c23ea3719947d790d4fffd17152a37d0fe551b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QPrivateSignal: disable implicit conversions from initializer_listGiuseppe D'Angelo2022-10-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The whole point of QPrivateSignal is to forbid anyone but the class itself from emitting a certain signal. This is a "workaround" introduced in Qt 5.0, due to the fact that the PMF syntax for connections requires users to take the address of a signal, and that is only possible if the signal itself is public. (In fact, signals were protected in Qt 4.) The Q_OBJECT macro defines the private QPrivateSignal class. A QObject subclass that wants to "protect" its signal emissions can declare a signal carrying an argument of type QPrivateSignal: signals: void aSignal(int, QPrivateSignal); If the class itself wants to emit the signal, it can do so: emit aSignal(42, QPrivateSignal()); But if "someone else" wants to, they can't use the QPrivateSignal type because it's private. emit obj.aSignal(42, SomeClass::QPrivateSignal()); // ERROR Here's a hair in this soup: list initialization. If a braced-init-list is used, [over.ics.list] simply *ignores* access control. This allows an "untyped" initializer-list to match QPrivateSignal and perform aggregate initialization: emit obj.aSignal(42, {}); // works! This kind of defeats the whole purpose. Therefore: make QPrivateSignal not an aggregate and give it an explicit default constructor, disabling copy-list-initialization for it. This means that using `{}` will fail to compile (class is no longer an aggregate, a constructor must be selected, and copy-list-initialization will not select an explicit constructor). This isn't a complete fix by any means. There's always the possibility of using enough template magic to extract QPrivateSignal's type (e.g. as a local alias) and then create an object of that type; but that sounds extremely unlikely to be happening "by accident" (whilst it's super-easy to just type {} as the argument and not realize that you were not supposed to do so). [ChangeLog][QtCore][Potentially Source-Incompatible Changes] It is no longer possible to use `{}` to construct a QPrivateSignal object (specifically, QPrivateSignal's default constructor is now explicit). This means that emitting a signal that carries a QPrivateSignal argument (i.e. a "private signal") cannot any longer be done by using something like `emit aSignal({})`; instead, such usages must be ported to `emit aSignal(QPrivateSignal());` or equivalent. Change-Id: Iac379aee3a8adca5a91d5db906a61bfcd0abc89f Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* JNI: add generic support for array-typesVolker Hilsheimer2022-10-101-32/+45
| | | | | | | | | | | | | | | | | | | The typeSignature for a type T[] is always "[" + typeSignature<t>, so we can just implicitly support arrays of any known type. To prevent support for multi-dimensional arrays, make sure that the underlying type is not also an array. By adding a QJniTypes::isArrayType in addition (that is true for any type with a signature starting with '['), methods like QJniObject::callMethod could then return a special QJniArray type that provides array-specific functionality. As a drive-by, and since all lines need to be touched to add braces, replace std::is_same<>::value with std::is_same_v. Change-Id: Iccadf03cfceb8544381a8f635bb54baeddf46c99 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* qpoll: disallow file descriptors bigger than FD_SETSIZEThiago Macieira2022-10-101-0/+5
| | | | | | | | | | | I don't know which platforms qpoll.cpp is still used and if in those there's even a way to increase the file descriptor limit above FD_SETSIZE's. But this is an easy change and protects against buffer overruns. Pick-to: 6.4 Change-Id: I810d70e579eb4e2c8e45fffd1718ca1aac8e6bef Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Replace qExchange with std::exchangeMarc Mutz2022-10-072-4/+4
| | | | | | | | | | | | | None of these users require C++20 constexpr or C++23 noexcept, the only remaining difference between std::exchange and qExchange. This leaves a single qExchange() user, in QScopedValueRollback, that requires the constexpr version, only available from C++20, and thus remains unported. Task-number: QTBUG-99313 Change-Id: Iea46f6ed61d6bd8a5b2fd9d9ec4d70c980b443a2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qcore_mac_p.h: compile-optimize inline swap functionsMarc Mutz2022-10-071-6/+6
| | | | | | | | | | | | | | | | | Instead of using the overly-generic qSwap() monster, use - qt_ptr_swap() for swapping raw pointers - member-swap for swapping smart pointers - std::swap() for swapping scalars In QtCore, this has proven to give a nice reduction in compile time for Qt users, cf. b1b0c2970e480ef460a61f37fa430dc443390358. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-97601 Change-Id: Iad8e6c11ebcc3ff822479c36f5faff88992b1165 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Fix indentation in QSharedMemory docsTor Arne Vestbø2022-10-061-42/+41
| | | | | Change-Id: I99293a51bf001bbf3bf6a4afeee332a4bcca2a65 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>