diff options
author | Marc Mutz <marc.mutz@qt.io> | 2024-01-18 08:54:18 +0100 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2024-01-25 17:37:48 +0000 |
commit | 8d88f1282bb614ba8fdc0990f733f74639a13cea (patch) | |
tree | dfe9849c4bbb459eb5687a55cf615a5f0ca038be | |
parent | 6d1b4d574021bc2d036e61526b01a2dea5876b5b (diff) |
QMetaTypeModuleHelper: fix -Wweak-vtable
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>
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 6 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype_p.h | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index a1310992f4..ebe79e0232 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -948,6 +948,12 @@ void QMetaType::unregisterMetaType(QMetaType type) than the QMetaType \a b, otherwise returns \c false. */ +/*! \internal */ +bool QMetaTypeModuleHelper::convert(const void *, int, void *, int) const +{ + return false; +} + #define QT_ADD_STATIC_METATYPE(MetaTypeName, MetaTypeId, RealName) \ { #RealName, sizeof(#RealName) - 1, MetaTypeId }, diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h index 71a225d5e6..7e0457771f 100644 --- a/src/corelib/kernel/qmetatype_p.h +++ b/src/corelib/kernel/qmetatype_p.h @@ -38,20 +38,21 @@ QT_BEGIN_NAMESPACE assign_and_return \ } -class QMetaTypeModuleHelper +class Q_CORE_EXPORT QMetaTypeModuleHelper { Q_DISABLE_COPY_MOVE(QMetaTypeModuleHelper) protected: QMetaTypeModuleHelper() = default; ~QMetaTypeModuleHelper() = default; public: + Q_WEAK_OVERLOAD // prevent it from entering the ABI and rendering constexpr useless static constexpr auto makePair(int from, int to) -> quint64 { return (quint64(from) << 32) + quint64(to); } virtual const QtPrivate::QMetaTypeInterface *interfaceForType(int) const = 0; - virtual bool convert(const void *, int, void *, int) const { return false; } + virtual bool convert(const void *, int, void *, int) const; }; extern Q_CORE_EXPORT const QMetaTypeModuleHelper *qMetaTypeGuiHelper; |