diff options
Diffstat (limited to 'src/corelib/global/qtypeinfo.h')
-rw-r--r-- | src/corelib/global/qtypeinfo.h | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index 4f79c48c51..636dc24c07 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -49,6 +49,26 @@ QT_BEGIN_NAMESPACE QTypeInfo - type trait functionality */ +template <typename T> +static constexpr bool qIsRelocatable() +{ +#if defined(Q_CC_CLANG) || !defined(Q_CC_GNU) || Q_CC_GNU >= 501 + return std::is_trivially_copyable<T>::value && std::is_trivially_destructible<T>::value; +#else + return std::is_enum<T>::value || std::is_integral<T>::value; +#endif +} + +template <typename T> +static constexpr bool qIsTrivial() +{ +#if defined(Q_CC_CLANG) || !defined(Q_CC_GNU) || Q_CC_GNU >= 501 + return std::is_trivial<T>::value; +#else + return std::is_enum<T>::value || std::is_integral<T>::value; +#endif +} + /* The catch-all template. */ @@ -61,9 +81,9 @@ public: isSpecialized = std::is_enum<T>::value, // don't require every enum to be marked manually isPointer = false, isIntegral = std::is_integral<T>::value, - isComplex = !isIntegral && !std::is_enum<T>::value, + isComplex = !qIsTrivial<T>(), isStatic = true, - isRelocatable = std::is_enum<T>::value, + isRelocatable = qIsRelocatable<T>(), isLarge = (sizeof(T)>sizeof(void*)), isDummy = false, //### Qt6: remove sizeOf = sizeof(T) @@ -248,9 +268,9 @@ class QTypeInfo<TYPE > \ public: \ enum { \ isSpecialized = true, \ - isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \ + isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0) && !qIsTrivial<TYPE>(), \ isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \ - isRelocatable = !isStatic || ((FLAGS) & Q_RELOCATABLE_TYPE), \ + isRelocatable = !isStatic || ((FLAGS) & Q_RELOCATABLE_TYPE) || qIsRelocatable<TYPE>(), \ isLarge = (sizeof(TYPE)>sizeof(void*)), \ isPointer = false, \ isIntegral = std::is_integral< TYPE >::value, \ @@ -288,7 +308,7 @@ Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE); #define Q_DECLARE_SHARED_IMPL(TYPE, FLAGS) \ Q_DECLARE_TYPEINFO(TYPE, FLAGS); \ inline void swap(TYPE &value1, TYPE &value2) \ - Q_DECL_NOEXCEPT_EXPR(noexcept(value1.swap(value2))) \ + noexcept(noexcept(value1.swap(value2))) \ { value1.swap(value2); } #define Q_DECLARE_SHARED(TYPE) Q_DECLARE_SHARED_IMPL(TYPE, Q_MOVABLE_TYPE) #define Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(TYPE) \ |