From fc85a6b6b952aa619b87262d4187dc05865ab51a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 6 Oct 2018 22:33:57 +0200 Subject: QTypeInfo: use C++11 type traits to deduce if a type is static or complex All types that can be trivially copied and destructed are by definition relocatable, and we should apply those semantics when moving them in memory. Types that are trivial, are by definition not complex and should be treated as such. [ChangeLog][QtCore] Qt Containers and meta type system now use C++11 type traits (std::is_trivial, std::is_trivially_copyable and std::is_trivially_destructible) to detect the class of a type not explicitly set by Q_DECLARE_TYPEINFO. (Q_DECLARE_TYPEINFO is still needed for QList.) Done-with: Olivier Goffart (Woboq GmbH) Change-Id: Iebb87ece425ea919e86169d06cd509c54a074282 Reviewed-by: Thiago Macieira --- src/corelib/global/qtypeinfo.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/corelib/global/qtypeinfo.h') diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index 4f79c48c51..567ff5c08e 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 +static constexpr bool qIsRelocatable() +{ +#if defined(Q_CC_CLANG) || !defined(Q_CC_GNU) || Q_CC_GNU >= 501 + return std::is_trivially_copyable::value && std::is_trivially_destructible::value; +#else + return std::is_enum::value || std::is_integral::value; +#endif +} + +template +static constexpr bool qIsTrivial() +{ +#if defined(Q_CC_CLANG) || !defined(Q_CC_GNU) || Q_CC_GNU >= 501 + return std::is_trivial::value; +#else + return std::is_enum::value || std::is_integral::value; +#endif +} + /* The catch-all template. */ @@ -61,9 +81,9 @@ public: isSpecialized = std::is_enum::value, // don't require every enum to be marked manually isPointer = false, isIntegral = std::is_integral::value, - isComplex = !isIntegral && !std::is_enum::value, + isComplex = !qIsTrivial(), isStatic = true, - isRelocatable = std::is_enum::value, + isRelocatable = qIsRelocatable(), isLarge = (sizeof(T)>sizeof(void*)), isDummy = false, //### Qt6: remove sizeOf = sizeof(T) @@ -248,9 +268,9 @@ class QTypeInfo \ public: \ enum { \ isSpecialized = true, \ - isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \ + isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0) && !qIsTrivial(), \ isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \ - isRelocatable = !isStatic || ((FLAGS) & Q_RELOCATABLE_TYPE), \ + isRelocatable = !isStatic || ((FLAGS) & Q_RELOCATABLE_TYPE) || qIsRelocatable(), \ isLarge = (sizeof(TYPE)>sizeof(void*)), \ isPointer = false, \ isIntegral = std::is_integral< TYPE >::value, \ -- cgit v1.2.3 From 8d7c97d428cdf89c3419a4e13b62a9849feefce9 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 4 Apr 2019 16:46:41 +0200 Subject: Remove remaining Q_DECL_NOEXCEPT/Q_DECL_NOTHROW usage Change-Id: I91ac9e714a465cab226b211812aa46e8fe5ff2ab Reviewed-by: Thiago Macieira --- src/corelib/global/qtypeinfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/global/qtypeinfo.h') diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index 567ff5c08e..636dc24c07 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -308,7 +308,7 @@ Q_DECLARE_TYPEINFO_BODY(QFlags, 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) \ -- cgit v1.2.3