summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-06-21 11:08:58 -0700
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-29 02:40:02 +0000
commit5a3e04686424b984211b9a2fa27cb60cc0a4244b (patch)
tree55a76c582245580c0e9bb34c43289a89587ec169
parent956a14650ba3d16f96a689deb0743afe2f44990d (diff)
moc: fix const-init for Windows
References to __declspec(dllimport) is not a constant expression on Windows, so we can't have a direct reference to a staticMetaObject. Commit 9b8493314dd77f3e96b353187816bb7ef4dedbb5 fixed the Q_OBJECT parent link (added in 5.14, kicked in for 6.0 with the ABI break), but commit 656d6f2a9b221dbd5adfc46262cb243e696d8d62 added links for Q_GADGETs too without taking the need for Windows DLLs into account. This change is a no-op everywhere but Windows. On Windows, since we store the pointer to the indirect getter function, now you may get non- null pointers from QMetaObject::superClass(). Change-Id: I6d3880c7d99d4fc494c8fffd16fab51aa255106e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 688e8f63a2bb87469517166f90c50dec524f90c5) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/kernel/qobjectdefs.h3
-rw-r--r--src/tools/moc/generator.cpp7
2 files changed, 5 insertions, 5 deletions
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index 0fca56f703..8309e43d89 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -369,6 +369,7 @@ struct Q_CORE_EXPORT QMetaObject
}
struct SuperData {
+ using Getter = const QMetaObject *(*)();
const QMetaObject *direct;
SuperData() = default;
constexpr SuperData(std::nullptr_t) : direct(nullptr) {}
@@ -377,7 +378,6 @@ struct Q_CORE_EXPORT QMetaObject
constexpr const QMetaObject *operator->() const { return operator const QMetaObject *(); }
#ifdef QT_NO_DATA_RELOCATION
- using Getter = const QMetaObject *(*)();
Getter indirect = nullptr;
constexpr SuperData(Getter g) : direct(nullptr), indirect(g) {}
constexpr operator const QMetaObject *() const
@@ -385,6 +385,7 @@ struct Q_CORE_EXPORT QMetaObject
template <const QMetaObject &MO> static constexpr SuperData link()
{ return SuperData(QMetaObject::staticMetaObject<MO>); }
#else
+ constexpr SuperData(Getter g) : direct(g()) {}
constexpr operator const QMetaObject *() const
{ return direct; }
template <const QMetaObject &MO> static constexpr SuperData link()
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp
index 701622862f..de939c2c48 100644
--- a/src/tools/moc/generator.cpp
+++ b/src/tools/moc/generator.cpp
@@ -489,16 +489,15 @@ void Generator::generateCode()
//
// Finally create and initialize the static meta object
//
- fprintf(out, "%sconst QMetaObject %s::staticMetaObject = { {\n",
- // ### FIXME: gadgets are not constinit on Windows!
- cdef->hasQGadget ? "" : "Q_CONSTINIT ", cdef->qualified.constData());
+ fprintf(out, "Q_CONSTINIT const QMetaObject %s::staticMetaObject = { {\n",
+ cdef->qualified.constData());
if (isQObject)
fprintf(out, " nullptr,\n");
else if (cdef->superclassList.size() && !cdef->hasQGadget && !cdef->hasQNamespace) // for qobject, we know the super class must have a static metaobject
fprintf(out, " QMetaObject::SuperData::link<%s::staticMetaObject>(),\n", purestSuperClass.constData());
else if (cdef->superclassList.size()) // for gadgets we need to query at compile time for it
- fprintf(out, " QtPrivate::MetaObjectForType<%s>::value(),\n", purestSuperClass.constData());
+ fprintf(out, " QtPrivate::MetaObjectForType<%s>::value,\n", purestSuperClass.constData());
else
fprintf(out, " nullptr,\n");
fprintf(out, " qt_meta_stringdata_%s.offsetsAndSizes,\n"