From 0db329e48d071a89108d3dcc91df6f3fc4efe7b0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 22 Jul 2022 18:12:55 -0700 Subject: [PATCH] QVariant: add noexcept to fromValue when possible Even though it's calling a noexcept(false) constructor, we can declare when it it won't throw and allow the caller to suppress its own exception handling. This necessitated splitting the Q_DECLARE_SHARED into its components because fromValue uses QTypeInfo::isRelocatable. Change-Id: I3859764fed084846bcb0fffd1704503aa4d3e535 Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qvariant.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 5e7b2e0fdf..3a59a37549 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -51,6 +51,7 @@ class QVariant; template inline T qvariant_cast(const QVariant &); +template<> constexpr inline bool qIsRelocatable = true; class Q_CORE_EXPORT QVariant { struct CborValueStandIn { qint64 n; void *c; int t; }; @@ -429,8 +430,9 @@ public: template #ifndef Q_CLANG_QDOC - static inline auto fromValue(const T &value) -> - std::enable_if_t, QVariant> + static inline auto fromValue(const T &value) + noexcept(std::is_nothrow_copy_constructible_v && Private::CanUseInternalSpace) + -> std::enable_if_t && std::is_destructible_v, QVariant> #else static inline QVariant fromValue(const T &value) #endif @@ -517,7 +519,7 @@ inline QVariant QVariant::fromValue(const QVariant &value) } template<> -inline QVariant QVariant::fromValue(const std::monostate &) +inline QVariant QVariant::fromValue(const std::monostate &) noexcept { return QVariant(); } @@ -556,7 +558,8 @@ QT_WARNING_POP inline bool QVariant::isDetached() const { return !d.is_shared || d.data.shared->ref.loadRelaxed() == 1; } -Q_DECLARE_SHARED(QVariant) +inline void swap(QVariant &value1, QVariant &value2) noexcept +{ value1.swap(value2); } #ifndef QT_MOC