summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-10-09 15:54:01 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-12 13:04:27 +0200
commitd9f9bc9bada91e3ec2b6c496d3b2242506ca56bc (patch)
treee9b38267bae5e84ac73cff38c5daafed9aaddf4b /src/corelib
parentb1e234b2242b7ed1ce4001ae29abecf5ae74fadf (diff)
QMetaType: Avoid combination of extern and declspec(__dllexport) on MSVC
MSVC does strange things with this, and it actually tells us so via a warning. We can, however, attach the dllexport to the definition, rather than the declaration of the symbols in order to resolve the problem. Change-Id: I9971e13afc6d8840c49ec20d21820a72c5407200 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qmetatype.cpp11
-rw-r--r--src/corelib/kernel/qmetatype.h13
2 files changed, 19 insertions, 5 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 60588e9329..c9a0a40cd0 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -2925,14 +2925,23 @@ QMetaType::QMetaType(int typeId) : QMetaType(interfaceForType(typeId)) {}
namespace QtPrivate {
#ifndef QT_BOOTSTRAPPED
+
+#if defined(Q_CC_MSVC) && defined(QT_BUILD_CORE_LIB)
+#define QT_METATYPE_TEMPLATE_EXPORT Q_CORE_EXPORT
+#else
+#define QT_METATYPE_TEMPLATE_EXPORT
+#endif
+
// Explicit instantiation definition
-#define QT_METATYPE_DECLARE_TEMPLATE_ITER(TypeName, Id, Name) template class QMetaTypeForType<Name>;
+#define QT_METATYPE_DECLARE_TEMPLATE_ITER(TypeName, Id, Name) \
+ template class QT_METATYPE_TEMPLATE_EXPORT QMetaTypeForType<Name>;
QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QT_METATYPE_DECLARE_TEMPLATE_ITER)
QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QT_METATYPE_DECLARE_TEMPLATE_ITER)
QT_FOR_EACH_STATIC_CORE_CLASS(QT_METATYPE_DECLARE_TEMPLATE_ITER)
QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_DECLARE_TEMPLATE_ITER)
QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_DECLARE_TEMPLATE_ITER)
#undef QT_METATYPE_DECLARE_TEMPLATE_ITER
+#undef QT_METATYPE_TEMPLATE_EXPORT
#endif
}
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index a6631dc2d9..2f6303deb4 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -2228,10 +2228,15 @@ public:
#undef QT_METATYPE_CONSTEXPRLAMDA
#ifndef QT_BOOTSTRAPPED
+
+#if !defined(Q_CC_MSVC) || !defined(QT_BUILD_CORE_LIB)
+#define QT_METATYPE_TEMPLATE_EXPORT Q_CORE_EXPORT
+#else
+#define QT_METATYPE_TEMPLATE_EXPORT
+#endif
+
#define QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER(TypeName, Id, Name) \
- extern template class Q_CORE_EXPORT QMetaTypeForType<Name>;
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_MSVC(4910) // '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation
+ extern template class QT_METATYPE_TEMPLATE_EXPORT QMetaTypeForType<Name>;
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wattributes") // false positive because of QMetaTypeForType<void>
QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER)
@@ -2240,8 +2245,8 @@ QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER)
QT_FOR_EACH_STATIC_CORE_CLASS(QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER)
QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER)
QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER)
-QT_WARNING_POP
#undef QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER
+#undef QT_METATYPE_TEMPLATE_EXPORT
#endif
template<typename T>