diff options
-rw-r--r-- | src/corelib/global/qglobal.h | 6 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant_p.h | 22 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 99328d52ac..d0d6e851ad 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -415,9 +415,15 @@ QT_END_INCLUDE_NAMESPACE #ifdef Q_COMPILER_EXPLICIT_OVERRIDES # define Q_DECL_OVERRIDE override # define Q_DECL_FINAL final +# ifdef Q_COMPILER_DECLTYPE // required for class-level final to compile in qvariant_p.h +# define Q_DECL_FINAL_CLASS final +# else +# define Q_DECL_FINAL_CLASS +# endif #else # define Q_DECL_OVERRIDE # define Q_DECL_FINAL +# define Q_DECL_FINAL_CLASS #endif //defines the type for the WNDPROC on windows diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index a754bc4363..65d346c470 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -203,6 +203,19 @@ class QVariantIsNull /// \internal /// This class checks if a type T has method called isNull. Result is kept in the Value property /// TODO Can we somehow generalize it? A macro version? +#if defined(Q_COMPILER_DECLTYPE) // C++11 version + template<typename T> + class HasIsNullMethod { + struct Yes { char unused[1]; }; + struct No { char unused[2]; }; + Q_STATIC_ASSERT(sizeof(Yes) != sizeof(No)); + + template<class C> static decltype(static_cast<const C*>(0)->isNull(), Yes()) test(int); + template<class C> static No test(...); + public: + static const bool Value = (sizeof(test<T>(0)) == sizeof(Yes)); + }; +#else // C++98 version (doesn't work for final classes) template<typename T, bool IsClass = QTypeInfo<T>::isComplex> class HasIsNullMethod { @@ -211,7 +224,7 @@ class QVariantIsNull Q_STATIC_ASSERT(sizeof(Yes) != sizeof(No)); struct FallbackMixin { bool isNull() const; }; - struct Derived : public T, public FallbackMixin {}; + struct Derived : public T, public FallbackMixin {}; // <- doesn't work for final classes template<class C, C> struct TypeCheck {}; template<class C> static Yes test(...); @@ -227,6 +240,7 @@ class QVariantIsNull public: static const bool Value = false; }; +#endif // TODO This part should go to autotests during HasIsNullMethod generalization. Q_STATIC_ASSERT(!HasIsNullMethod<bool>::Value); @@ -236,6 +250,12 @@ class QVariantIsNull Q_STATIC_ASSERT(!HasIsNullMethod<SelfTest2>::Value); struct SelfTest3 : public SelfTest1 {}; Q_STATIC_ASSERT(HasIsNullMethod<SelfTest3>::Value); + struct SelfTestFinal1 Q_DECL_FINAL_CLASS { bool isNull() const; }; + Q_STATIC_ASSERT(HasIsNullMethod<SelfTestFinal1>::Value); + struct SelfTestFinal2 Q_DECL_FINAL_CLASS {}; + Q_STATIC_ASSERT(!HasIsNullMethod<SelfTestFinal2>::Value); + struct SelfTestFinal3 Q_DECL_FINAL_CLASS : public SelfTest1 {}; + Q_STATIC_ASSERT(HasIsNullMethod<SelfTestFinal3>::Value); template<typename T, bool HasIsNull = HasIsNullMethod<T>::Value> struct CallFilteredIsNull |