Cleanup QTypeInfo

Remove QTypeInfo::isStatic, as that's not used anymore in Qt 6.
Also remove sizeOf, it's unused, and we have QMetaType for that if
required.
Remove all typeinfo declaractions for trivial types, as the default
template covers them correctly nowadays.

Finally set up a better default for isPointer, and do some smaller
cleanups all over the place.

Change-Id: I6758ed37dfc701feaaf0ff105cc95e32da9f9c33
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2020-08-20 18:31:06 +02:00
parent db21bad936
commit acbf9a858b
16 changed files with 62 additions and 167 deletions

View File

@ -55,16 +55,7 @@ class QDebug;
*/ */
template <typename T> template <typename T>
static constexpr bool qIsRelocatable() static constexpr bool qIsRelocatable = std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T>;
{
return std::is_trivially_copyable<T>::value && std::is_trivially_destructible<T>::value;
}
template <typename T>
static constexpr bool qIsTrivial()
{
return std::is_trivial<T>::value;
}
/* /*
The catch-all template. The catch-all template.
@ -75,12 +66,10 @@ class QTypeInfo
{ {
public: public:
enum { enum {
isPointer = false, isPointer = std::is_pointer_v<T>,
isIntegral = std::is_integral<T>::value, isIntegral = std::is_integral_v<T>,
isComplex = !qIsTrivial<T>(), isComplex = !std::is_trivial_v<T>,
isStatic = true, isRelocatable = qIsRelocatable<T>,
isRelocatable = qIsRelocatable<T>(),
sizeOf = sizeof(T)
}; };
}; };
@ -92,52 +81,10 @@ public:
isPointer = false, isPointer = false,
isIntegral = false, isIntegral = false,
isComplex = false, isComplex = false,
isStatic = false,
isRelocatable = false, isRelocatable = false,
sizeOf = 0
}; };
}; };
template <typename T>
class QTypeInfo<T*>
{
public:
enum {
isPointer = true,
isIntegral = false,
isComplex = false,
isStatic = false,
isRelocatable = true,
sizeOf = sizeof(T*)
};
};
/*!
\class QTypeInfoQuery
\inmodule QtCore
\internal
\brief QTypeInfoQuery is used to query the values of a given QTypeInfo<T>
We use it because there may be some QTypeInfo<T> specializations in user
code that don't provide certain flags that we added after Qt 5.0. They are:
\list
\li isRelocatable: defaults to !isStatic
\endlist
DO NOT specialize this class elsewhere.
*/
// apply defaults for a generic QTypeInfo<T> that didn't provide the new values
template <typename T, typename = void>
struct QTypeInfoQuery : public QTypeInfo<T>
{
enum { isRelocatable = !QTypeInfo<T>::isStatic };
};
// if QTypeInfo<T>::isRelocatable exists, use it
template <typename T>
struct QTypeInfoQuery<T, typename std::enable_if<QTypeInfo<T>::isRelocatable || true>::type> : public QTypeInfo<T>
{};
/*! /*!
\class QTypeInfoMerger \class QTypeInfoMerger
\inmodule QtCore \inmodule QtCore
@ -163,12 +110,10 @@ class QTypeInfoMerger
{ {
static_assert(sizeof...(Ts) > 0); static_assert(sizeof...(Ts) > 0);
public: public:
static constexpr bool isComplex = ((QTypeInfoQuery<Ts>::isComplex) || ...); static constexpr bool isComplex = ((QTypeInfo<Ts>::isComplex) || ...);
static constexpr bool isStatic = ((QTypeInfoQuery<Ts>::isStatic) || ...); static constexpr bool isRelocatable = ((QTypeInfo<Ts>::isRelocatable) && ...);
static constexpr bool isRelocatable = ((QTypeInfoQuery<Ts>::isRelocatable) && ...);
static constexpr bool isPointer = false; static constexpr bool isPointer = false;
static constexpr bool isIntegral = false; static constexpr bool isIntegral = false;
static constexpr std::size_t sizeOf = sizeof(T);
}; };
#define Q_DECLARE_MOVABLE_CONTAINER(CONTAINER) \ #define Q_DECLARE_MOVABLE_CONTAINER(CONTAINER) \
@ -182,8 +127,6 @@ public: \
isIntegral = false, \ isIntegral = false, \
isComplex = true, \ isComplex = true, \
isRelocatable = true, \ isRelocatable = true, \
isStatic = false, \
sizeOf = sizeof(CONTAINER<T>) \
}; \ }; \
} }
@ -204,9 +147,7 @@ public: \
isPointer = false, \ isPointer = false, \
isIntegral = false, \ isIntegral = false, \
isComplex = true, \ isComplex = true, \
isStatic = false, \
isRelocatable = true, \ isRelocatable = true, \
sizeOf = sizeof(CONTAINER<K, V>) \
}; \ }; \
} }
@ -228,10 +169,9 @@ Q_DECLARE_MOVABLE_CONTAINER(QMultiHash);
enum { /* TYPEINFO flags */ enum { /* TYPEINFO flags */
Q_COMPLEX_TYPE = 0, Q_COMPLEX_TYPE = 0,
Q_PRIMITIVE_TYPE = 0x1, Q_PRIMITIVE_TYPE = 0x1,
Q_STATIC_TYPE = 0, Q_RELOCATABLE_TYPE = 0x2,
Q_MOVABLE_TYPE = 0x2, // ### Qt6: merge movable and relocatable once QList no longer depends on it Q_MOVABLE_TYPE = 0x2,
Q_DUMMY_TYPE = 0x4, Q_DUMMY_TYPE = 0x4,
Q_RELOCATABLE_TYPE = 0x8
}; };
#define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS) \ #define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS) \
@ -239,14 +179,11 @@ class QTypeInfo<TYPE > \
{ \ { \
public: \ public: \
enum { \ enum { \
isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0) && !qIsTrivial<TYPE>(), \ isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0) && !std::is_trivial_v<TYPE>, \
isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \ isRelocatable = !isComplex || ((FLAGS) & Q_RELOCATABLE_TYPE) || qIsRelocatable<TYPE>, \
isRelocatable = !isStatic || ((FLAGS) & Q_RELOCATABLE_TYPE) || qIsRelocatable<TYPE>(), \
isPointer = false, \ isPointer = false, \
isIntegral = std::is_integral< TYPE >::value, \ isIntegral = std::is_integral< TYPE >::value, \
sizeOf = sizeof(TYPE) \
}; \ }; \
static inline const char *name() { return #TYPE; } \
} }
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS) \ #define Q_DECLARE_TYPEINFO(TYPE, FLAGS) \
@ -283,50 +220,6 @@ inline void swap(TYPE &value1, TYPE &value2) \
#define Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(TYPE) \ #define Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(TYPE) \
Q_DECLARE_SHARED_IMPL(TYPE, QT_VERSION >= QT_VERSION_CHECK(6,0,0) ? Q_MOVABLE_TYPE : Q_RELOCATABLE_TYPE) Q_DECLARE_SHARED_IMPL(TYPE, QT_VERSION >= QT_VERSION_CHECK(6,0,0) ? Q_MOVABLE_TYPE : Q_RELOCATABLE_TYPE)
/*
QTypeInfo primitive specializations
*/
Q_DECLARE_TYPEINFO(bool, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(char, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(signed char, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(uchar, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(short, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(ushort, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(int, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(uint, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(long, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(ulong, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(qint64, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(quint64, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(float, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(double, Q_PRIMITIVE_TYPE);
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
// ### Qt 6: remove the other branch
// This was required so that QList<T> for these types allocates out of the array storage
Q_DECLARE_TYPEINFO(long double, Q_PRIMITIVE_TYPE);
# ifdef Q_COMPILER_UNICODE_STRINGS
Q_DECLARE_TYPEINFO(char16_t, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(char32_t, Q_PRIMITIVE_TYPE);
# endif
# if !defined(Q_CC_MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
Q_DECLARE_TYPEINFO(wchar_t, Q_PRIMITIVE_TYPE);
# endif
#else
# ifndef Q_OS_DARWIN
Q_DECLARE_TYPEINFO(long double, Q_PRIMITIVE_TYPE);
# else
Q_DECLARE_TYPEINFO(long double, Q_RELOCATABLE_TYPE);
# endif
# ifdef Q_COMPILER_UNICODE_STRINGS
Q_DECLARE_TYPEINFO(char16_t, Q_RELOCATABLE_TYPE);
Q_DECLARE_TYPEINFO(char32_t, Q_RELOCATABLE_TYPE);
# endif
# if !defined(Q_CC_MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
Q_DECLARE_TYPEINFO(wchar_t, Q_RELOCATABLE_TYPE);
# endif
#endif // Qt 6
namespace QTypeTraits namespace QTypeTraits
{ {

View File

@ -1459,7 +1459,7 @@ namespace QtPrivate {
template<typename T> template<typename T>
struct QMetaTypeTypeFlags struct QMetaTypeTypeFlags
{ {
enum { Flags = (QTypeInfoQuery<T>::isRelocatable ? QMetaType::MovableType : 0) enum { Flags = (QTypeInfo<T>::isRelocatable ? QMetaType::MovableType : 0)
| (QTypeInfo<T>::isComplex ? QMetaType::NeedsConstruction : 0) | (QTypeInfo<T>::isComplex ? QMetaType::NeedsConstruction : 0)
| (QTypeInfo<T>::isComplex ? QMetaType::NeedsDestruction : 0) | (QTypeInfo<T>::isComplex ? QMetaType::NeedsDestruction : 0)
| (IsPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::PointerToQObject : 0) | (IsPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::PointerToQObject : 0)

View File

@ -174,7 +174,7 @@ struct QArrayExceptionSafetyPrimitives
T *const end; T *const end;
qsizetype displace; qsizetype displace;
static_assert(QTypeInfoQuery<T>::isRelocatable, "Type must be relocatable"); static_assert(QTypeInfo<T>::isRelocatable, "Type must be relocatable");
Displacer(T *start, T *finish, qsizetype diff) noexcept Displacer(T *start, T *finish, qsizetype diff) noexcept
: begin(start), end(finish), displace(diff) : begin(start), end(finish), displace(diff)
@ -201,7 +201,7 @@ struct QArrayExceptionSafetyPrimitives
size_t n; size_t n;
qsizetype &size; qsizetype &size;
static_assert(QTypeInfoQuery<T>::isRelocatable, "Type must be relocatable"); static_assert(QTypeInfo<T>::isRelocatable, "Type must be relocatable");
Mover(T *&start, size_t length, qsizetype &sz) noexcept Mover(T *&start, size_t length, qsizetype &sz) noexcept
: destination(start), source(start), n(length), size(sz) : destination(start), source(start), n(length), size(sz)
@ -1018,7 +1018,7 @@ struct QArrayOpsSelector
template <class T> template <class T>
struct QArrayOpsSelector<T, struct QArrayOpsSelector<T,
typename std::enable_if< typename std::enable_if<
!QTypeInfoQuery<T>::isComplex && QTypeInfoQuery<T>::isRelocatable !QTypeInfo<T>::isComplex && QTypeInfo<T>::isRelocatable
>::type> >::type>
{ {
typedef QPodArrayOps<T> Type; typedef QPodArrayOps<T> Type;
@ -1027,7 +1027,7 @@ struct QArrayOpsSelector<T,
template <class T> template <class T>
struct QArrayOpsSelector<T, struct QArrayOpsSelector<T,
typename std::enable_if< typename std::enable_if<
QTypeInfoQuery<T>::isComplex && QTypeInfoQuery<T>::isRelocatable QTypeInfo<T>::isComplex && QTypeInfo<T>::isRelocatable
>::type> >::type>
{ {
typedef QMovableArrayOps<T> Type; typedef QMovableArrayOps<T> Type;

View File

@ -61,7 +61,7 @@ namespace QtPrivate
template <typename T, typename N> template <typename T, typename N>
void q_uninitialized_relocate_n(T* first, N n, T* out) void q_uninitialized_relocate_n(T* first, N n, T* out)
{ {
if constexpr (QTypeInfoQuery<T>::isRelocatable) { if constexpr (QTypeInfo<T>::isRelocatable) {
if (n != N(0)) { // even if N == 0, out == nullptr or first == nullptr are UB for memmove() if (n != N(0)) { // even if N == 0, out == nullptr or first == nullptr are UB for memmove()
std::memmove(static_cast<void*>(out), std::memmove(static_cast<void*>(out),
static_cast<const void*>(first), static_cast<const void*>(first),
@ -69,7 +69,7 @@ void q_uninitialized_relocate_n(T* first, N n, T* out)
} }
} else { } else {
std::uninitialized_move_n(first, n, out); std::uninitialized_move_n(first, n, out);
if constexpr (QTypeInfoQuery<T>::isComplex) if constexpr (QTypeInfo<T>::isComplex)
std::destroy_n(first, n); std::destroy_n(first, n);
} }
} }

View File

@ -429,7 +429,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::realloc(qsizetype asize,
a = Prealloc; a = Prealloc;
} }
s = 0; s = 0;
if (!QTypeInfoQuery<T>::isRelocatable) { if (!QTypeInfo<T>::isRelocatable) {
QT_TRY { QT_TRY {
// move all the old elements // move all the old elements
while (s < copySize) { while (s < copySize) {
@ -556,7 +556,7 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
if (n != 0) { if (n != 0) {
resize(s + n); resize(s + n);
const T copy(t); const T copy(t);
if (!QTypeInfoQuery<T>::isRelocatable) { if (!QTypeInfo<T>::isRelocatable) {
T *b = ptr + offset; T *b = ptr + offset;
T *j = ptr + s; T *j = ptr + s;
T *i = j - n; T *i = j - n;

View File

@ -108,12 +108,6 @@ template <int N, int M, typename T>
class QTypeInfo<QGenericMatrix<N, M, T> > class QTypeInfo<QGenericMatrix<N, M, T> >
: public QTypeInfoMerger<QGenericMatrix<N, M, T>, T> : public QTypeInfoMerger<QGenericMatrix<N, M, T>, T>
{ {
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
public:
enum {
isStatic = true,
}; // at least Q_RELOCATABLE_TYPE, for BC during Qt 5
#endif
}; };
template <int N, int M, typename T> template <int N, int M, typename T>
@ -350,7 +344,7 @@ QDebug operator<<(QDebug dbg, const QGenericMatrix<N, M, T> &m)
{ {
QDebugStateSaver saver(dbg); QDebugStateSaver saver(dbg);
dbg.nospace() << "QGenericMatrix<" << N << ", " << M dbg.nospace() << "QGenericMatrix<" << N << ", " << M
<< ", " << QTypeInfo<T>::name() << ", " << QMetaType::fromType<T>().name()
<< ">(" << Qt::endl << qSetFieldWidth(10); << ">(" << Qt::endl << qSetFieldWidth(10);
for (int row = 0; row < M; ++row) { for (int row = 0; row < M; ++row) {
for (int col = 0; col < N; ++col) for (int col = 0; col < N; ++col)

View File

@ -152,7 +152,7 @@ enum class MyStrictNoOpEnum { StrictZero, StrictOne, StrictTwo, StrictFour=4 };
Q_DECLARE_FLAGS( MyStrictNoOpFlags, MyStrictNoOpEnum ) Q_DECLARE_FLAGS( MyStrictNoOpFlags, MyStrictNoOpEnum )
static_assert( !QTypeInfo<MyStrictFlags>::isComplex ); static_assert( !QTypeInfo<MyStrictFlags>::isComplex );
static_assert( !QTypeInfo<MyStrictFlags>::isStatic ); static_assert( QTypeInfo<MyStrictFlags>::isRelocatable );
static_assert( !QTypeInfo<MyStrictFlags>::isPointer ); static_assert( !QTypeInfo<MyStrictFlags>::isPointer );
void tst_QFlags::classEnum() void tst_QFlags::classEnum()
@ -322,7 +322,7 @@ Q_DECLARE_FLAGS( MyFlags, MyEnum )
Q_DECLARE_OPERATORS_FOR_FLAGS( MyFlags ) Q_DECLARE_OPERATORS_FOR_FLAGS( MyFlags )
static_assert( !QTypeInfo<MyFlags>::isComplex ); static_assert( !QTypeInfo<MyFlags>::isComplex );
static_assert( !QTypeInfo<MyFlags>::isStatic ); static_assert( QTypeInfo<MyFlags>::isRelocatable );
static_assert( !QTypeInfo<MyFlags>::isPointer ); static_assert( !QTypeInfo<MyFlags>::isPointer );
QTEST_MAIN(tst_QFlags) QTEST_MAIN(tst_QFlags)

View File

@ -919,6 +919,11 @@ FOR_EACH_CORE_METATYPE(RETURN_CREATE_COPY_FUNCTION)
TypeTestFunctionGetter::get(type)(); TypeTestFunctionGetter::get(type)();
} }
template<typename T>
constexpr size_t getSize = sizeof(T);
template<>
constexpr size_t getSize<void> = 0;
void tst_QMetaType::sizeOf_data() void tst_QMetaType::sizeOf_data()
{ {
QTest::addColumn<int>("type"); QTest::addColumn<int>("type");
@ -926,7 +931,7 @@ void tst_QMetaType::sizeOf_data()
QTest::newRow("QMetaType::UnknownType") << int(QMetaType::UnknownType) << size_t(0); QTest::newRow("QMetaType::UnknownType") << int(QMetaType::UnknownType) << size_t(0);
#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << size_t(QTypeInfo<RealType>::sizeOf); QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << getSize<RealType>;
FOR_EACH_CORE_METATYPE(ADD_METATYPE_TEST_ROW) FOR_EACH_CORE_METATYPE(ADD_METATYPE_TEST_ROW)
#undef ADD_METATYPE_TEST_ROW #undef ADD_METATYPE_TEST_ROW
@ -1074,8 +1079,8 @@ void tst_QMetaType::flags_data()
#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
QTest::newRow(#RealType) << MetaTypeId \ QTest::newRow(#RealType) << MetaTypeId \
<< bool(QTypeInfoQuery<RealType>::isRelocatable) \ << bool(QTypeInfo<RealType>::isRelocatable) \
<< bool(QTypeInfoQuery<RealType>::isComplex) \ << bool(QTypeInfo<RealType>::isComplex) \
<< bool(QtPrivate::IsPointerToTypeDerivedFromQObject<RealType>::Value) \ << bool(QtPrivate::IsPointerToTypeDerivedFromQObject<RealType>::Value) \
<< bool(std::is_enum<RealType>::value); << bool(std::is_enum<RealType>::value);
QT_FOR_EACH_STATIC_CORE_CLASS(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_CORE_CLASS(ADD_METATYPE_TEST_ROW)

View File

@ -3187,7 +3187,7 @@ template<class T> void playWithVariant(const T &orig, bool isNull, const QString
{ {
QVariant v2 = v; QVariant v2 = v;
if (!(QTypeInfo<T>::isStatic && QTypeInfo<T>::isComplex)) { if (QTypeInfo<T>::isRelocatable) {
// Type is movable so standard comparison algorithm in QVariant should work // Type is movable so standard comparison algorithm in QVariant should work
// In a custom type QVariant is not aware of ==operator so it won't be called, // In a custom type QVariant is not aware of ==operator so it won't be called,
// which may cause problems especially visible when using a not-movable type // which may cause problems especially visible when using a not-movable type
@ -3204,7 +3204,7 @@ template<class T> void playWithVariant(const T &orig, bool isNull, const QString
v = QVariant(); v = QVariant();
QCOMPARE(v3, v); QCOMPARE(v3, v);
v = v2; v = v2;
if (!(QTypeInfo<T>::isStatic && QTypeInfo<T>::isComplex)) { if (QTypeInfo<T>::isRelocatable) {
// Type is movable so standard comparison algorithm in QVariant should work // Type is movable so standard comparison algorithm in QVariant should work
// In a custom type QVariant is not aware of ==operator so it won't be called, // In a custom type QVariant is not aware of ==operator so it won't be called,
// which may cause problems especially visible when using a not-movable type // which may cause problems especially visible when using a not-movable type

View File

@ -1880,7 +1880,7 @@ void tst_QByteArray::movablity()
{ {
QFETCH(QByteArray, array); QFETCH(QByteArray, array);
static_assert(!QTypeInfo<QByteArray>::isStatic); static_assert(QTypeInfo<QByteArray>::isRelocatable);
const int size = array.size(); const int size = array.size();
const bool isEmpty = array.isEmpty(); const bool isEmpty = array.isEmpty();

View File

@ -800,9 +800,12 @@ void tst_QArrayData::arrayOps()
}; };
const CountedObject objArray[5]; const CountedObject objArray[5];
QVERIFY(!QTypeInfo<int>::isComplex && !QTypeInfo<int>::isStatic); static_assert(!QTypeInfo<int>::isComplex);
QVERIFY(QTypeInfo<QString>::isComplex && !QTypeInfo<QString>::isStatic); static_assert(QTypeInfo<int>::isRelocatable);
QVERIFY(QTypeInfo<CountedObject>::isComplex && QTypeInfo<CountedObject>::isStatic); static_assert(QTypeInfo<QString>::isComplex);
static_assert(QTypeInfo<QString>::isRelocatable);
static_assert(QTypeInfo<CountedObject>::isComplex);
static_assert(!QTypeInfo<CountedObject>::isRelocatable);
QCOMPARE(CountedObject::liveCount, size_t(5)); QCOMPARE(CountedObject::liveCount, size_t(5));
for (size_t i = 0; i < 5; ++i) for (size_t i = 0; i < 5; ++i)

View File

@ -184,11 +184,11 @@ inline size_t qHash(const Custom &key, size_t seed = 0) { return qHash(key.i, se
Q_DECLARE_METATYPE(Custom); Q_DECLARE_METATYPE(Custom);
// tests depends on the fact that: // tests depends on the fact that:
static_assert(!QTypeInfo<int>::isStatic); static_assert(QTypeInfo<int>::isRelocatable);
static_assert(!QTypeInfo<int>::isComplex); static_assert(!QTypeInfo<int>::isComplex);
static_assert(!QTypeInfo<Movable>::isStatic); static_assert(QTypeInfo<Movable>::isRelocatable);
static_assert(QTypeInfo<Movable>::isComplex); static_assert(QTypeInfo<Movable>::isComplex);
static_assert(QTypeInfo<Custom>::isStatic); static_assert(!QTypeInfo<Custom>::isRelocatable);
static_assert(QTypeInfo<Custom>::isComplex); static_assert(QTypeInfo<Custom>::isComplex);
@ -2144,7 +2144,7 @@ void tst_QList::resizePOD_data() const
QTest::addColumn<int>("size"); QTest::addColumn<int>("size");
QVERIFY(!QTypeInfo<int>::isComplex); QVERIFY(!QTypeInfo<int>::isComplex);
QVERIFY(!QTypeInfo<int>::isStatic); QVERIFY(QTypeInfo<int>::isRelocatable);
QList<int> null; QList<int> null;
QList<int> empty(0, 5); QList<int> empty(0, 5);
@ -2192,7 +2192,7 @@ void tst_QList::resizeComplexMovable_data() const
QTest::addColumn<int>("size"); QTest::addColumn<int>("size");
QVERIFY(QTypeInfo<Movable>::isComplex); QVERIFY(QTypeInfo<Movable>::isComplex);
QVERIFY(!QTypeInfo<Movable>::isStatic); QVERIFY(QTypeInfo<Movable>::isRelocatable);
QList<Movable> null; QList<Movable> null;
QList<Movable> empty(0, 'Q'); QList<Movable> empty(0, 'Q');
@ -2244,7 +2244,7 @@ void tst_QList::resizeComplex_data() const
QTest::addColumn<int>("size"); QTest::addColumn<int>("size");
QVERIFY(QTypeInfo<Custom>::isComplex); QVERIFY(QTypeInfo<Custom>::isComplex);
QVERIFY(QTypeInfo<Custom>::isStatic); QVERIFY(!QTypeInfo<Custom>::isRelocatable);
QList<Custom> null; QList<Custom> null;
QList<Custom> empty(0, '0'); QList<Custom> empty(0, '0');

View File

@ -43,7 +43,7 @@ private Q_SLOTS:
void testDeductionRules(); void testDeductionRules();
}; };
class C { C() {} Q_DECL_UNUSED_MEMBER char _[4]; }; class C { C() {} ~C() {} Q_DECL_UNUSED_MEMBER char _[4]; };
class M { M() {} Q_DECL_UNUSED_MEMBER char _[4]; }; class M { M() {} Q_DECL_UNUSED_MEMBER char _[4]; };
class P { Q_DECL_UNUSED_MEMBER char _[4]; }; class P { Q_DECL_UNUSED_MEMBER char _[4]; };
@ -64,31 +64,31 @@ typedef QPair<P,M> QPairPM;
typedef QPair<P,P> QPairPP; typedef QPair<P,P> QPairPP;
static_assert( QTypeInfo<QPairCC>::isComplex); static_assert( QTypeInfo<QPairCC>::isComplex);
static_assert( QTypeInfo<QPairCC>::isStatic ); static_assert( !QTypeInfo<QPairCC>::isRelocatable );
static_assert( QTypeInfo<QPairCM>::isComplex); static_assert( QTypeInfo<QPairCM>::isComplex);
static_assert( QTypeInfo<QPairCM>::isStatic ); static_assert( !QTypeInfo<QPairCM>::isRelocatable );
static_assert( QTypeInfo<QPairCP>::isComplex); static_assert( QTypeInfo<QPairCP>::isComplex);
static_assert( QTypeInfo<QPairCP>::isStatic ); static_assert( !QTypeInfo<QPairCP>::isRelocatable );
static_assert( QTypeInfo<QPairMC>::isComplex); static_assert( QTypeInfo<QPairMC>::isComplex);
static_assert( QTypeInfo<QPairMC>::isStatic ); static_assert( !QTypeInfo<QPairMC>::isRelocatable );
static_assert( QTypeInfo<QPairMM>::isComplex); static_assert( QTypeInfo<QPairMM>::isComplex);
static_assert(!QTypeInfo<QPairMM>::isStatic ); static_assert( QTypeInfo<QPairMM>::isRelocatable );
static_assert( QTypeInfo<QPairMP>::isComplex); static_assert( QTypeInfo<QPairMP>::isComplex);
static_assert(!QTypeInfo<QPairMP>::isStatic ); static_assert( QTypeInfo<QPairMP>::isRelocatable );
static_assert( QTypeInfo<QPairPC>::isComplex); static_assert( QTypeInfo<QPairPC>::isComplex);
static_assert( QTypeInfo<QPairPC>::isStatic ); static_assert( !QTypeInfo<QPairPC>::isRelocatable );
static_assert( QTypeInfo<QPairPM>::isComplex); static_assert( QTypeInfo<QPairPM>::isComplex);
static_assert(!QTypeInfo<QPairPM>::isStatic ); static_assert( QTypeInfo<QPairPM>::isRelocatable );
static_assert(!QTypeInfo<QPairPP>::isComplex); static_assert(!QTypeInfo<QPairPP>::isComplex);
static_assert(!QTypeInfo<QPairPP>::isStatic ); static_assert( QTypeInfo<QPairPP>::isRelocatable );
static_assert(!QTypeInfo<QPairPP>::isPointer); static_assert(!QTypeInfo<QPairPP>::isPointer);

View File

@ -528,11 +528,11 @@ void reallocTest()
typedef QVarLengthArray<T, 16> Container; typedef QVarLengthArray<T, 16> Container;
enum { enum {
isStatic = QTypeInfo<T>::isStatic, isRelocatable = QTypeInfo<T>::isRelocatable,
isComplex = QTypeInfo<T>::isComplex, isComplex = QTypeInfo<T>::isComplex,
isPrimitive = !isComplex && !isStatic, isPrimitive = !isComplex && isRelocatable,
isMovable = !isStatic isMovable = isRelocatable
}; };
// Constructors // Constructors

View File

@ -325,7 +325,7 @@ void tst_QGuiMetaType::flags_data()
QTest::addColumn<bool>("isComplex"); QTest::addColumn<bool>("isComplex");
#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
QTest::newRow(#RealType) << MetaTypeId << bool(QTypeInfoQuery<RealType>::isRelocatable) << bool(QTypeInfoQuery<RealType>::isComplex); QTest::newRow(#RealType) << MetaTypeId << bool(QTypeInfo<RealType>::isRelocatable) << bool(QTypeInfo<RealType>::isComplex);
QT_FOR_EACH_STATIC_GUI_CLASS(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_GUI_CLASS(ADD_METATYPE_TEST_ROW)
#undef ADD_METATYPE_TEST_ROW #undef ADD_METATYPE_TEST_ROW
} }

View File

@ -361,7 +361,7 @@ void QRawVector<T>::realloc(int asize, int aalloc, bool ref)
T *xbegin = m_begin; T *xbegin = m_begin;
if (aalloc != xalloc || ref) { if (aalloc != xalloc || ref) {
// (re)allocate memory // (re)allocate memory
if (QTypeInfo<T>::isStatic) { if (!QTypeInfo<T>::isRelocatable) {
xbegin = allocate(aalloc); xbegin = allocate(aalloc);
xsize = 0; xsize = 0;
changed = true; changed = true;
@ -462,7 +462,7 @@ typename QRawVector<T>::iterator QRawVector<T>::insert(iterator before, size_typ
const T copy(t); const T copy(t);
if (m_size + n > m_alloc) if (m_size + n > m_alloc)
realloc(m_size, QVectorData::grow(offsetOfTypedData(), m_size + n, sizeof(T)), false); realloc(m_size, QVectorData::grow(offsetOfTypedData(), m_size + n, sizeof(T)), false);
if (QTypeInfo<T>::isStatic) { if (!QTypeInfo<T>::isRelocatable) {
T *b = m_begin + m_size; T *b = m_begin + m_size;
T *i = m_begin + m_size + n; T *i = m_begin + m_size + n;
while (i != b) while (i != b)