diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/global/qtypeinfo.h | 9 | ||||
| -rw-r--r-- | src/corelib/tools/qcontainertools_impl.h | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index f89bf72635e..9b2119da1df 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -97,6 +97,11 @@ public: [[deprecated("Use std::is_pointer instead")]] static constexpr bool isPointer = false; [[deprecated("Use std::is_integral instead")]] static constexpr bool isIntegral = false; static constexpr bool isValueInitializationBitwiseZero = false; + static_assert(!isRelocatable || + std::is_copy_constructible_v<T> || + std::is_move_constructible_v<T>, + "All Ts... are Q_RELOCATABLE_TYPE, but T is neither copy- nor move-constructible, " + "so cannot be Q_RELOCATABLE_TYPE. Please mark T as Q_COMPLEX_TYPE manually."); }; // QTypeInfo for std::pair: @@ -158,6 +163,10 @@ public: \ isIntegral [[deprecated("Use std::is_integral instead")]] = std::is_integral< TYPE >::value, \ isValueInitializationBitwiseZero = QtPrivate::qIsValueInitializationBitwiseZero<TYPE>, \ }; \ + static_assert(!isRelocatable || \ + std::is_copy_constructible_v<TYPE > || \ + std::is_move_constructible_v<TYPE >, \ + #TYPE " is neither copy- nor move-constructible, so cannot be Q_RELOCATABLE_TYPE"); \ } #define Q_DECLARE_TYPEINFO(TYPE, FLAGS) \ diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h index 40ed0a84e96..d66705ef4d4 100644 --- a/src/corelib/tools/qcontainertools_impl.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -72,6 +72,8 @@ template <typename T, typename N> void q_uninitialized_relocate_n(T* first, N n, T* out) { if constexpr (QTypeInfo<T>::isRelocatable) { + static_assert(std::is_copy_constructible_v<T> || std::is_move_constructible_v<T>, + "Refusing to relocate this non-copy/non-move-constructible type."); if (n != N(0)) { // even if N == 0, out == nullptr or first == nullptr are UB for memcpy() std::memcpy(static_cast<void *>(out), static_cast<const void *>(first), |
