QFlags: mark as Q_PRIMITIVE_TYPE
I originally tried to put Q_DECLARE_TYPEINFOs into Q_DECLARE_OPERATORS_FOR_FLAGS, to declare not only the flags type, but also the underlying enum as primitive, but too many users (arguably correctly) used Q_DECLARE_OPERATORS_FOR_FLAGS at (non-global) namespace scope where QTypeInfo would have been specialised in the wrong namespace. So specialise QTypeInfo for QFlags<T> only. Change-Id: I4af6e29aefbd9460a3d2bc6405f03cdf6b1096bc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
3f1a4be302
commit
ff004175bc
@ -161,6 +161,10 @@ public: \
|
||||
template<> \
|
||||
Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS)
|
||||
|
||||
/* Specialize QTypeInfo for QFlags<T> */
|
||||
template<typename T> class QFlags;
|
||||
template<typename T>
|
||||
Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE);
|
||||
|
||||
/*
|
||||
Specialize a shared type with:
|
||||
|
@ -123,6 +123,15 @@ void tst_QFlags::constExpr()
|
||||
#endif
|
||||
}
|
||||
|
||||
// (statically) check QTypeInfo for QFlags instantiations:
|
||||
enum MyEnum { Zero, One, Two, Four=4 };
|
||||
Q_DECLARE_FLAGS( MyFlags, MyEnum );
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS( MyFlags );
|
||||
|
||||
Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isComplex );
|
||||
Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isStatic );
|
||||
Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isLarge );
|
||||
Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isPointer );
|
||||
|
||||
QTEST_MAIN(tst_QFlags)
|
||||
#include "tst_qflags.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user