QMetaType::fromType: support classes with inaccessible dtors

Change-Id: I60a1b2496d48651a8166173b420da37f59d7a395
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Fabian Kosmale 2020-02-28 15:27:53 +01:00
parent b6446a5ffa
commit 98ca319819
2 changed files with 20 additions and 1 deletions

View File

@ -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) {

View File

@ -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;