From e15dd3f1696ae8a49b1bbde6fccadf8091c979d7 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 18 Jan 2024 08:54:18 +0100 Subject: [PATCH] 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 Change-Id: I2ce4a7110e09def1a595d717c073df844213611c Reviewed-by: Thiago Macieira (cherry picked from commit 8d88f1282bb614ba8fdc0990f733f74639a13cea) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qmetatype.cpp | 6 ++++++ 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 dd023c9d20e..42133290863 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -939,6 +939,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 71a225d5e6e..7e0457771f0 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;