summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QMetaTypeCustomRegistry: use QHash::removeIf() instead of a custom erasing loopVladimir Belyavsky2024-04-211-7/+1
| | | | | | | | | | | | | | Use QHash::removeIf() instead of a custom erasing loop on aliases table when unregister custom type. It will still always detach even if nothing needs to be removed, since QHash::removeIf() always detaches. But this can potentially be fixed in the future, so it will be improved indirectly. Besides other things this also silences Clazy's "mixing iterators" warning. Change-Id: I3d6e8b0ed7dc10807570a0b0feac7eda6a0e572a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove unused includes in qmetatype.cppVladimir Belyavsky2024-04-211-2/+1
| | | | | | | | - Remove unused <bitset> - Place <qobject.h> under !(QT_BOOTSTRAPPED), because it seems used only there Change-Id: Ic77c7441d2400cf32e7b6ca2b90a1984a0b6377a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaType: allow converting to/from QChar and char16_tThiago Macieira2024-04-181-0/+3
| | | | | | | | Converting from char16_t to QString was already possible, going through a QChar. Change-Id: Ie28eadac333c4bcd8c08fffd17c5a41488ea5ba6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QMetaType: add conversion from charXX_t to QStringThiago Macieira2024-04-181-0/+10
| | | | | Change-Id: I3c79b7e08fa346988dfefffd171f9c97384af5d0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Bootstrap: remove QVariantThiago Macieira2024-03-131-10/+12
| | | | | | | | | I added QT_NO_VARIANT to qconfig-bootstrapped.h to be clearer on what the #ifs are, but there's no testing of that feature outside of QT_BOOTSTRAPPED. Change-Id: I01ec3c774d9943adb903fffd17b7e8ac4340fb89 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Bootstrap: remove QDataStreamThiago Macieira2024-03-131-1/+2
| | | | | | | | | | | It was only used by the cmake_automoc_parser so it would write a 64-bit in big-endian format. So bypass QDataStream and write it native endianness. Change-Id: I01ec3c774d9943adb903fffd17b79c78e56db4cf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
* QMetaTypeModuleHelper: fix -Wweak-vtableMarc Mutz2024-01-251-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | The only implemented virtual function, convert(), is inline, so the vtable and type_info for this class were duplicated in QtGui, QtWidgets, and any other library that may use this. Fix by exporting the class and de-inlining convert(). The vtable is now pinned to qmetatype.cpp. To prevent MSVC from exporting the trivial static helper function and possibly rendering its constexpr non-functional, make it a template. We have two macros for this purpose, with different semantics: The Q_WEAK_OVERLOAD macro is related to overload set management, not to keeping function out of the ABI, even though it does that, too. And we have QT_POST_CXX17_API_IN_EXPORTED_CLASS for ABI control, but this function is not using post-C++17 features, so since both macros need a comment, and both don't fit 100%, I used the shorter one. Task-number: QTBUG-45582 Pick-to: 6.7 Change-Id: I2ce4a7110e09def1a595d717c073df844213611c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaTypeModuleHelper: mark instances constexprMarc Mutz2024-01-191-1/+1
| | | | | | | | | | Static and thread-local objects should be constexpr or constinit if possible. Task-number: QTBUG-100485 Pick-to: 6.7 6.6 6.5 Change-Id: I29088798a50d6278252c9088e7c191c4214b2e5b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaTypeModuleHelper: suppress cppcoreguidelines-virtual-class-destructorMarc Mutz2024-01-181-0/+1
| | | | | | | | | | | | | | | | | | | | Says clang-tidy: destructor of '(unnamed struct at qmetatype.cpp:966:14)' is public and non-virtual in file:src/corelib/kernel/qmetatype.cpp line:966 col:14 static const struct : QMetaTypeModuleHelper Yes, these classes are polymorphic (because the base class is). Yes, the destructor is non-virtual (because the base class' one isn't, but it's also protected, so fine). But these classes are not used as base classes, so suppress the warning. Pick-to: 6.7 6.6 6.5 6.2 Change-Id: I75be86bca36a4a0e93d72acb1a0d2fe0dca1c505 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: Assert on consistency when unregisteringUlf Hermann2024-01-171-6/+15
| | | | | | | | | If we are trying to unregister a metatype with an ID that belongs to a different metatype, then something is very wrong. Change-Id: I3191557883b69030f91c3aca7f359acf2dde66e7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaType: s/QPair/std::pair/Marc Mutz2023-12-141-17/+14
| | | | | | | | | | | | Also port from qMakePair() to just braced initialization and CTAD. As a drive-by, use auto instead of various const QMetaType::*Function* so statements fit on one line again, and port from `typedef` to `using`. Pick-to: 6.7 Task-number: QTBUG-115841 Change-Id: I6bd9747fb9eb34da08053927507f2008d9bbfb86 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Doc: Fix template information for QMetaType membersLuca Di Sera2023-11-181-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When QDoc parses a project, it parses the source code to extract the user-provided documentation and perform sanity checkings based on the code itself on it. When QDoc parses an "\fn" command as part of this process, it tries to understand, based on its intermediate representation built on the information extracted from the code-base, which "documentable element" the "\fn" refers to. When QDoc performs this "matching" process, it takes into consideration only a certain amount of information. For example, no checking is performed over the template declaration of a callable. Due to some upcoming documentation, where two callables are indistinguishable to the current process, as they differ only in their template declaration, QDoc will start to take into consideration the template declaration of a callable when matching. This implies that an "\fn" command should now provide information parity, with regards to template declaration for callables, with the code-base so that QDoc can perform the match correctly. The documentation for some of the members of `QMetaType` is not in sync with the intended target template declaration. Hence, add the missing information to the relevant "\fn" commands. Task-number: QTBUG-118080 Change-Id: I642bbc1ab90e3cc0d32a11592ab5ad93bd181364 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* QMetaType[docs]: fix 'constructor' typoMårten Nordheim2023-07-041-1/+1
| | | | | | Pick-to: 6.6 6.5 Change-Id: I7dedf635b9a5e85f6af49bf0a5e0348dde32e80d Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Fix crash in `QVariant::convert` and `QVariant::view`Jøger Hansegård2023-07-021-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `QVariant::convert` may lead to crash or produce garbage data when attempting to convert a gadget between a pointer type and a value type, for example from a variant holding a QLocale gadget to a QLocale* pointer and vice versa. Similarly, `QVariant::view` may crash under the same conditions. The reason is that conversion is implemented through copy construction assuming that both source and target types are either both pointers or both values. If converting from pointer to value type, the result is crash during destruction of the QVariant. If converting from value to pointer type, the result is a QVariant holding a pointer to garbage data (and possibly crash if pointer is dereferenced). Similarly, if attempting to convert a pointer to a QObject derived type to its value type, the system crashes, with a slightly different failure mode. During `QVariant::convert`, a temporary `QVariant` of the target type is created. Since objects that can not be copy constructed are invalid for `QVariant`, the temporary is left empty without constructing the target value. Then, when attempting to convert from a pointer type to a value type, the temporary's destructor is incorrectly called on the owned object. Since the owned object is never constructed, this leads to a crash. The proposed fix is to return false from `QMetaType::view`, `QMetaType::canView`, `QMetaType::convert`, and `QMetaType::canConvert` if the target type is of different 'pointedness' than the source type. After this fix, converting and viewing gadgets and QObjects behaves the same way as primitive types and core types, which already returned false when converting between value type and pointer type. Fixes: QTBUG-114797 Pick-to: 6.5 6.6 Change-Id: If5ad764a60f2f3c912070198073b28999d995f17 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QMetaType: more doc tidies for the flagsGiuseppe D'Angelo2023-04-161-3/+3
| | | | | | Change-Id: I354b2dc901ecb1b2baa717c74e265e9201d8e63e Pick-to: 6.5 6.2 5.15 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QMetaType::IsGadget: doc tidiesGiuseppe D'Angelo2023-04-161-1/+1
| | | | | | | | | Although undocumented (which is weird, as other docs refer to it), fix the spelling and the formatting. Change-Id: Ief8b04e3b9272386c663c463c3659e8b837260f5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
* QMetaType: Provide underlyingType for enumsFabian Kosmale2023-03-281-0/+54
| | | | | | | | | | | | | | | | | | | | | | Currently, Qt assumes that enums always have int as their underlying type (both in QMetaEnum::keyToValue and in the QML engine). This change makes it possible to to retrieve the underlying type from an enum's metaype - or rather, a metatype of an integral type with the same size and signedness. The use cases aobve don't really rely on the exact same type. In most cases, we wouldn't even need the signedness, however that is already available anyway, and it will come in handy once QML supports bigint, and we need to decide whether we should return While it would be possible for individual users of this function to manually query the size and signedness, having a function returning a metatype offers additional convenience - especially in QML, where the conversion APIs generally operate on metatypes. Task-number: QTBUG-27451 Task-number: QTBUG-84055 Task-number: QTBUG-112180 Change-Id: Icf733b42df0ea64017d69f4d94cb7c855d9e3201 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QMetaType::convert: Avoid some copies in ranged-forFabian Kosmale2023-03-211-4/+4
| | | | | | | | Found by static analysis. Change-Id: I416eb31736c8c5002fb4906aae4272e645f1916d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaType: Ensure that qfloat16 gets correct idFabian Kosmale2023-03-141-0/+14
| | | | | | | | | | | | | | | | | | | Code initially compiled against Qt <= 6.2 does not have a qfloat16 metatype that unconditionally gets registeret from QtBase. Therefore, any preexisting metatype instance for qfloat16 will hit the custom type registry code path. As builtin metatypes are not part of the custom registry, we will create a new type-id, and the type will thus not compare equal to new code using the builtin type-id. Avoid this issue by inserting an alias to the type in QMetaTypeCustomRegistry's constructor. Change-Id: I825265ad16e274c08b2c4a3a4814475b6c6c6187 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit b68ad5ef7fd8df0ef4aea03f33dfe05fd8272469) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QMetaEnum: fix narrowing warnings related to valueToKey*()Ahmad Samir2023-03-131-2/+2
| | | | | | | | | | | | | | | | | valueToKey*() takes an int, and QMetaEnum internally assumes the underlying type of an enum is not bigger than int. Using static_cast as it's easier to search for it in the codebase if needed. Found by compiling with -Wshorten-64-to-32. Drive-by change: remove qdoc \fn command for qt_QMetaEnum_debugOperator, it's an internal method and defined right under the doc block (the signature still said "int" but it's qint64). Change-Id: Ia6abc85173bf94c0a8c56663481d83d3a998f68d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix QVariant(QString) <-> enum conversionChristian Ehrlicher2023-02-081-7/+8
| | | | | | | | | | | | | | A QVariant(QString) was not convertible to an enum not registered with Q_ENUM() which worked fine in Qt5. The same problem exists for QVariant(enum) to QString. Fix it by not bailing out when no metatype for the enum was found and try to convert it to a qlonglong instead (which is then correctly converted to the enum type). Fixes: QTBUG-109744 Pick-to: 6.5 6.4 Change-Id: Ie7bb016a860455b69508f0f46b36474c9c294f3a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaType: fix value-initialization in a corner caseGiuseppe D'Angelo2022-12-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a type is trivially default constructible, QMetaType (and QVariant) think that it can be built and value-initialized by zero-filling a region of storage and then "blessing" that storage as an actual instance of the type to build. This is done as an optimization. This doesn't work for all trivially constructible types. For instance, on the Itanium C++ ABI, pointers to data members are actually value-initialized (= zero-initialized, = initialized to null) with the value -1: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#data-member-pointers This means that a type like struct A { int A::*ptr; }; is trivially constructible, but its value initialization is not equivalent to zero-filling its storage. Since C++ does not offer a type trait we can use for the detection that we want to do here, and since we have also decided that Q_PRIMITIVE_TYPE isn't that trait (it just means trivially copyable / destructible), I'm rolling out a custom type trait for the purpose. This type trait is private for the moment being (there's no Q_DECLARE_TYPEINFO for it), and limited to the subset of scalar types that we know can be value-initialized by memset(0) into their storage (basically, all of them, except for pointers to data members). The fix tries to keep the pre-existing semantics of `QMetaType::NeedsConstruction`. Before, the flag was set for types which were not trivially default constructible. That included types that aren't default constructible, or types that cannot do so trivially. I've left that meaning unchanged, and simply amended the "trivial" part with the custom trait. A fix there (to clarify the semantics) can be done as a separate change. Change-Id: Id8da6acb913df83fc87e5d37e2349a4628e72e91 Pick-to: 6.5 Fixes: QTBUG-109594 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qfloat16: make it a built-in metatypeThiago Macieira2022-11-281-1/+6
| | | | | | | | | | | 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>
* 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>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* 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-151-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* QMetaType: Support custom unary converters with optional<To> return typeArno Rehn2022-09-271-1/+2
| | | | | | | | | | | | | | | To indicate success of a conversion, the public API has previously only supported registering member functions of the form To (From::*)(bool *). When adding custom converters for types that cannot be modified, this is usually not a possibility. As an alternative, this patch adds support for std::optional in the UnaryFunction overload of QMetaType::registerConverter. If the returned optional has no value, the conversion is considered failed. Task-number: QTBUG-92902 Change-Id: Ibac52d2cb9b5a2457081b4bebb0def1f03e3c55d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Include QVariantPair in documentation of QMetaType::TypeEdward Welbourne2022-09-261-0/+1
| | | | | | | | | | | | | | | When it was added, along with the type it describes, it wasn't added to the QDoc-only fake version of Type's declaration, or to the \enum's list of \value entries. There being no clear reason for those omissions, I'm presuming to guess they were just an oversight. This amends commit c7ce1bc05c1ec2f63dd2531f23a3e9f6fe866556 which was included in Qt 6.0.0. Pick-to: 6.2 6.4 Change-Id: I1bf9fe0f0a31219a888666550a197e479d8eadc1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clear two pointless entries from the QDoc-only QMetaType::TypeEdward Welbourne2022-09-261-2/+0
| | | | | | | | | | | The real Type has several "administrative" members beside LastCoreType and LastGuiType, but only these two appear in the qdoc-only fake version of Type, only to be \omitvalue'd out in the docs. Save the perpetual "need" to keep updating them with each new addition (they weren't even in sync with the real versions anyway) by removing them. Change-Id: If7c5da87655a2da5c7f29f394c9dd9921ff0c1a7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVariant: fix conversions of Q_ENUM that are QFlags<> to stringEirik Aavitsland2022-09-011-5/+13
| | | | | | | | | | The doc of QMetaEnum::valueToKey() says to use ::valueToKeys() instead for flag types. Pick-to: 6.4 Change-Id: I48e5ba47324137f2ce2710f1d876e93e7c562e9f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Doc: Update QMetaType::metaObject() descriptionsMike Trahearn2022-09-021-11/+13
| | | | | | | Pick-to: 6.4 6.3 6.2 5.15 Change-Id: Iff93f8fe2cf701d56d072e2593c76d49a70fc183 Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVariant: fix conversions of string keys to Q_ENUM that are QFlags<>Thiago Macieira2022-08-301-5/+11
| | | | | | | | | | | | | Since Qt 6.0, QMetaType stores the name obtained from the C++ compiler, which means we know a type like Qt::Alignment by its proper, full name of QFlags<Qt::AlignmentFlag>. However, the meta object records only the bare name of the enumeration, not the full flags. Pick-to: 6.2 6.3 6.4 Fixes: QTBUG-105932 Fixes: QTBUG-96185 Change-Id: Ic6547f8247454b47baa8fffd170eab977e306377 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix the spelling of the word "combination"Mike Trahearn2022-08-301-1/+1
| | | | | | Pick-to: 6.4 6.3 6.2 5.15 Change-Id: Ib6ad11d4fbbeefa280070125fd0ee6a64dababae Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QMetaType/Doc: update some wording about type registrationThiago Macieira2022-08-291-16/+13
| | | | | | | | | | | | | | | Type registration isn't necessary any more, unless you're trying to look up a name back to ID or QMetaType object. It hasn't been since 6.0. Drive-by update the example not to use deprecated API. Drive-by remove the paragraph about requirements that aren't accurate any more. Pick-to: 6.4 Task-number: QTBUG-104858 Change-Id: Ic6547f8247454b47baa8fffd170eecb66719fa65 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: don't create a registry just to query its emptiness [2/2]Marc Mutz2022-08-051-2/+2
| | | | | | | | | | The previous commit, b0e4d53b637e6c34457d14ed3f0be705098bf2f5, missed this one. Same rationale as back then. Pick-to: 6.4 6.3 Change-Id: Ibad4c130e0d61c64808275fa7b97b58ebd479acc Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaType: make all atomic operations explicitMarc Mutz2022-08-051-3/+4
| | | | | | | | | | In one case, optimize away an unnecessary extra load. Pick-to: 6.4 Task-number: QTBUG-103834 Change-Id: Iabbf58a09627dd2fd7a40c713a878d74cb522d60 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaType: prevent memory leak on create() if the constructor throwsThiago Macieira2022-07-271-13/+21
| | | | | | | | The #ifdef wasn't necessary because destroy() had been using __STDCPP_DEFAULT_NEW_ALIGNMENT__ without #if. Change-Id: I3859764fed084846bcb0fffd17039570283d3eaf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant: move the check for std::nullptr_t a bit up in customConstructThiago Macieira2022-07-271-5/+5
| | | | | | | | | | Avoids having to do work after QMetaType::construct() returns. That can't get the tail-call optimization right now because it is a non- inline non-static member function, so the QMetaType must be spilled to the stack. Change-Id: I3859764fed084846bcb0fffd1703a3ffc723f43f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: don't record trivial construction function pointersThiago Macieira2022-07-271-25/+26
| | | | | | | | | | | | We can implement the trivial {default,copy,move} construction outselves inside qmetatype.cpp and qvariant.cpp, simplifying the QMetaType interface object, removing up to three relocations per QMTI. This adds the testing for QMetaType::isXxxConstructible and isDestructible that couldn't be added before. Change-Id: Ic44396b31ba04712aab3fffd16ff0a28f541d507 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: add is{Default,Copy,Move}Constructible and isDestructibleThiago Macieira2022-07-261-2/+70
| | | | | | | | | | | Unit tests will come after I've fixed the flags themselves. At this point, they are wrong. [ChangeLog][QtCore][QMetaType] Added isDefaultConstructible(), isCopyConstructible(), isMoveConstructible() and isDestructible(). Change-Id: I3859764fed084846bcb0fffd170353109378e34c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: add registerType() and qRegisterMetaType(QMetaType)Thiago Macieira2022-07-261-18/+50
| | | | | | | | | | | | | | | | | | | | | | | This also rewrites QMetaType::id() on top of the helper, with the benefit of calling a member static function, so QMetaType doesn't need to be spilled onto the stack. In some upcoming changes I need to ensure that QMetaTypes are registered so they can be found by name and I'd like to have a dedicated function name for that, instead of calling .id(). Since I needed to add docs for the new function, I've updated for the old one too. [ChangeLog][QMetaType] Added QMetaType::registerType() and an overload of qRegisterMetaType() taking QMetaType (the two functions do the same thing). These two functions ensure a given QMetaType is registered with the Qt global registry, so they can be found by name later. Using qRegisterMetaType<T>() also accomplishes the same thing, but is slightly better for completely generic code because it will avoid emitting the registration for built-in types. Change-Id: I3859764fed084846bcb0fffd170351d606034c22 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: fix isRegistered()Thiago Macieira2022-07-261-3/+8
| | | | | | | | It's not registered until an ID is assigned. Pick-to: 6.4 Change-Id: I3859764fed084846bcb0fffd17034f5b369c5b4d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: fix documentationFabian Kosmale2022-07-211-7/+7
| | | | | | | | | The doc comments were missing the classname, and therefore did not show up in the correct places. Pick-to: 6.4 6.3 6.2 Change-Id: I23a56356dcad862e2fe1f6f8c3da2f39852b80c7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QMetaType: Do not warn about unknown types in isRegisteredFabian Kosmale2022-07-111-10/+16
| | | | | | | | | | | isRegistered naturally has the potential to run into unregistered types; in that case, we should not print any warning. Pick-to: 6.4 6.3 6.2 Change-Id: I060b23199ed1d41f67ebe656ed3c396094edffd4 Reviewed-by: Stefan Gehn <stefan.gehn@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live QDebug op<< QMetaType!Marc Mutz2022-07-091-0/+11
| | | | | | | | | | | It's needed in QtHttpServer. [ChangeLog][QtCore][QDebug] Can now stream QMetaType. [ChangeLog][QtCore][QMetaType] Can now be streamed through QDebug. Change-Id: I974d77d678137715472a3907ab1e50ba2dbaa087 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaType: move the built-in QMetaTypeInterfaces to read-only segmentsThiago Macieira2022-06-281-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The presence of the mutable causes the const object to lose its constness, so declaring as const wasn't helpful. But we can't drop the const wholesale for MSVC right now because it mangles the variable's type in the external name. For all other compilers, we drop it for user-defined types, which is a no-op but is semantically correct because QMetaType needs to modify those objects. Aside from a few const_cast (marked with comments), nothing else changes. For types with built-in type IDs, however, the QMetaTypeInterface is now fully const... or would be if it weren't full of relocations. It does move the lot from the .data section to the .data.rel.ro section. After this change, QtCore and QtGui have: QtCore QtGui .data.rel.ro 57 23 .data, exported 17 39 .data, private 94 193 sizeof(QtPrivate::QMetaTypeInterface) = 112 on 64-bit platforms (but GCC issues ".align 32", so they effectively occupy 128 bytes) Change-Id: Id0fb9ab0089845ee8843fffd16f9a35bfafebf77 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: extern-template the built-in Core types' QMetaTypeInterfaceThiago Macieira2022-06-281-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This *should* make no difference in behavior, it just prevents the instantiation of the QMetaTypeInterface and all the lambdas used in it in every compilation unit, with a copy in every library. Now, a simple function like: QMetaType f() { return QMetaType::fromType<int>(); } produces only a single function, with a reference into QtCore: _Z1fv: movq _ZN9QtPrivate25QMetaTypeInterfaceWrapperIiE8metaTypeE@GOTPCREL(%rip),%rax ret The code above *does* work on Windows, producing: _Z1fv: movq __imp__ZN9QtPrivate25QMetaTypeInterfaceWrapperIiE8metaTypeE(%rip), %rax ret However, it breaks the staticMetaObjects' metatype listing, because getting the address of a __declspec(dllimport) variable is not a constant expression (it lacks data relocations). So this is disabled on Windows. This change also broke the INTEGRITY build. I've simply disabled the optimization there without attempting to understand why it fails. Task-number: QTBUG-93471 Pick-to: 6.4 Change-Id: Id0fb9ab0089845ee8843fffd16f97748a00b4d64 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: use explicit load/store operations on QBasicAtomicIntThiago Macieira2022-06-181-4/+4
| | | | | | | | | QBasicAtomicInt::operator int() does loadAcquire() and operator=() does storeRelease(). Pick-to: 6.2 6.3 6.4 Change-Id: Id0fb9ab0089845ee8843fffd16f9a1ece6823777 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-40/+4
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>