summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qvariant.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-07-22 18:12:55 -0700
committerThiago Macieira <thiago.macieira@intel.com>2022-08-03 19:51:21 -0700
commit0db329e48d071a89108d3dcc91df6f3fc4efe7b0 (patch)
tree39c36e5a5f4474d0d4a16bf0cfbd8886f046e145 /src/corelib/kernel/qvariant.h
parent181aec92b650477ae6c6bf450f6fe3a29fbe81bd (diff)
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<QVariant> uses QTypeInfo<QVariant>::isRelocatable. Change-Id: I3859764fed084846bcb0fffd1704503aa4d3e535 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qvariant.h')
-rw-r--r--src/corelib/kernel/qvariant.h11
1 files 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<typename T>
inline T qvariant_cast(const QVariant &);
+template<> constexpr inline bool qIsRelocatable<QVariant> = true;
class Q_CORE_EXPORT QVariant
{
struct CborValueStandIn { qint64 n; void *c; int t; };
@@ -429,8 +430,9 @@ public:
template<typename T>
#ifndef Q_CLANG_QDOC
- static inline auto fromValue(const T &value) ->
- std::enable_if_t<std::is_copy_constructible_v<T>, QVariant>
+ static inline auto fromValue(const T &value)
+ noexcept(std::is_nothrow_copy_constructible_v<T> && Private::CanUseInternalSpace<T>)
+ -> std::enable_if_t<std::is_copy_constructible_v<T> && std::is_destructible_v<T>, 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