QMetaType::fromType: support classes with inaccessible dtors
Change-Id: I60a1b2496d48651a8166173b420da37f59d7a395 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
b6446a5ffa
commit
98ca319819
@ -2719,7 +2719,10 @@ QMetaTypeInterface QMetaTypeForType<T>::metaType = {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
/*.dtor=*/ QT_METATYPE_CONSTEXPRLAMDA( -> QMetaTypeInterface::DtorFn {
|
/*.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 {
|
/*.legacyRegisterOp=*/ QT_METATYPE_CONSTEXPRLAMDA( -> QMetaTypeInterface::LegacyRegisterOp {
|
||||||
if constexpr (QMetaTypeId2<T>::Defined && !QMetaTypeId2<T>::IsBuiltIn) {
|
if constexpr (QMetaTypeId2<T>::Defined && !QMetaTypeId2<T>::IsBuiltIn) {
|
||||||
|
@ -126,6 +126,7 @@ private slots:
|
|||||||
void fromType();
|
void fromType();
|
||||||
void operatorEq_data();
|
void operatorEq_data();
|
||||||
void operatorEq();
|
void operatorEq();
|
||||||
|
void typesWithInaccessibleDTors();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BaseGenericType
|
struct BaseGenericType
|
||||||
@ -2574,6 +2575,21 @@ void tst_QMetaType::operatorEq()
|
|||||||
QCOMPARE(typeB != typeA, !eq);
|
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
|
// Compile-time test, it should be possible to register function pointer types
|
||||||
class Undefined;
|
class Undefined;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user