From 2d8757f879d8f410319aae41ff902ba5a679d9dd Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 14 Jan 2021 23:23:37 +0100 Subject: QVariant::fromValue: require T to be copy constructible In Qt 5, QVariant::fromValue would not compile unless Q_DECLARE_METATYPE(T) was used, and Q_DECLARE_METATYPE(T) would lead to a compile error if T were not copy constructible. In Qt 6, we do not require Q_DECLARE_METATYPE before using fromValue, and QMetaType itself works with non-copy constructible types just fine. However, QVariant still requires it, thus we need to now enforce this in fromValue itself. Change-Id: Ib6964a438d8c46033dd3a037b9d871de2b42e175 Reviewed-by: Lars Knoll --- tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 6b30419bb8..23ee85ee46 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -68,6 +68,21 @@ class CustomNonQObject; +template +struct QVariantFromValueCompiles +{ + static inline constexpr bool value = false; +}; + +template +struct QVariantFromValueCompiles()))>> +{ + static inline constexpr bool value = true; +}; + +static_assert(QVariantFromValueCompiles::value); +static_assert(!QVariantFromValueCompiles::value); + class tst_QVariant : public QObject { Q_OBJECT -- cgit v1.2.3