From: Stephen Kelly Date: Tue, 24 Jul 2012 08:53:26 +0000 (+0200) Subject: Make qRegisterMetaType constexpr for built-in types. X-Git-Tag: v5.0.0-beta1~630 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dec9666dd4e6dc86d6d5a2520f0900c8ed508517;p=profile%2Fivi%2Fqtbase.git Make qRegisterMetaType constexpr for built-in types. For consistency with qMetaTypeId, and because we can. Change-Id: I6882a16ef3c0d84539048c9f2c201c4a2b2ca7ad Reviewed-by: Jędrzej Nowacki Reviewed-by: Marc Mutz --- diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 97a5bf4..6fc8333 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -639,7 +639,7 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId( } template -inline int qRegisterMetaType( +inline Q_DECL_CONSTEXPR int qRegisterMetaType( #if !defined(qdoc) && !defined(Q_CC_SUN) T * dummy = 0 #endif diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 230138d..b5169fe 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1681,11 +1681,19 @@ void tst_QMetaType::metaObject() #define METATYPE_ID_FUNCTION(Type, MetaTypeId, Name) \ case ::qMetaTypeId< Name >(): metaType = MetaTypeIdStruct::Value; +#define REGISTER_METATYPE_FUNCTION(Type, MetaTypeId, Name) \ + case qRegisterMetaType< Name >(): metaType = RegisterMetaTypeStruct::Value; + template struct MetaTypeIdStruct { }; +template +struct RegisterMetaTypeStruct +{ +}; + #define METATYPE_ID_STRUCT(Type, MetaTypeId, Name) \ template<> \ struct MetaTypeIdStruct< ::qMetaTypeId< Name >()> \ @@ -1693,14 +1701,28 @@ struct MetaTypeIdStruct< ::qMetaTypeId< Name >()> \ enum { Value = ::qMetaTypeId< Name >() }; \ }; +#define REGISTER_METATYPE_STRUCT(Type, MetaTypeId, Name) \ +template<> \ +struct RegisterMetaTypeStruct()> \ +{ \ + enum { Value = qRegisterMetaType< Name >() }; \ +}; + #if defined(Q_COMPILER_CONSTEXPR) QT_FOR_EACH_STATIC_TYPE(METATYPE_ID_STRUCT) +QT_FOR_EACH_STATIC_TYPE(REGISTER_METATYPE_STRUCT) template()> struct MetaTypeIdStructDefaultTemplateValue { enum { Value }; }; + +template()> +struct RegisterMetaTypeStructDefaultTemplateValue +{ + enum { Value }; +}; #endif void tst_QMetaType::constexprMetaTypeIds() @@ -1715,6 +1737,14 @@ void tst_QMetaType::constexprMetaTypeIds() #endif default:; } + + switch (id) { +#if defined(Q_COMPILER_CONSTEXPR) + QT_FOR_EACH_STATIC_TYPE(REGISTER_METATYPE_FUNCTION) + metaType = RegisterMetaTypeStructDefaultTemplateValue<>::Value; +#endif + default:; + } Q_UNUSED(metaType); }