diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-02-28 15:27:53 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-03-25 17:55:28 +0100 |
commit | 98ca31981977c5a265bb745cc70aafd17384d346 (patch) | |
tree | a6b88c7e4aa0a284f9f15f8efdf512ea9e9e715e | |
parent | b6446a5ffac55477d82da0492a9a41ce788275d5 (diff) |
QMetaType::fromType: support classes with inaccessible dtors
Change-Id: I60a1b2496d48651a8166173b420da37f59d7a395
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 5 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 16 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 0bec7ca4c0..1ae0fb45bc 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -2719,7 +2719,10 @@ QMetaTypeInterface QMetaTypeForType<T>::metaType = { } }), /*.dtor=*/ QT_METATYPE_CONSTEXPRLAMDA( -> QMetaTypeInterface::DtorFn { - return [](const QMetaTypeInterface *, void *addr) { reinterpret_cast<T *>(addr)->~T(); }; + if constexpr (std::is_destructible_v<T>) + return [](const QMetaTypeInterface *, void *addr) { reinterpret_cast<T *>(addr)->~T(); }; + else + return nullptr; }), /*.legacyRegisterOp=*/ QT_METATYPE_CONSTEXPRLAMDA( -> QMetaTypeInterface::LegacyRegisterOp { if constexpr (QMetaTypeId2<T>::Defined && !QMetaTypeId2<T>::IsBuiltIn) { diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 0d9dfc1c4c..f144aad7e4 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -126,6 +126,7 @@ private slots: void fromType(); void operatorEq_data(); void operatorEq(); + void typesWithInaccessibleDTors(); }; struct BaseGenericType @@ -2574,6 +2575,21 @@ void tst_QMetaType::operatorEq() QCOMPARE(typeB != typeA, !eq); } +class WithPrivateDTor { + ~WithPrivateDTor(){}; +}; + +struct WithDeletedDtor { + ~WithDeletedDtor() = delete; +}; + +void tst_QMetaType::typesWithInaccessibleDTors() +{ + // should compile + Q_UNUSED(QMetaType::fromType<WithPrivateDTor>()); + Q_UNUSED(QMetaType::fromType<WithDeletedDtor>()); +} + // Compile-time test, it should be possible to register function pointer types class Undefined; |