Require that the handle type used with QUniqueHandle is quite noexcept

QUniqueHandle is intended for handle types or opaque pointers that are
no-throw constructible, copyable, and assignable, and has nothrow
comparison and relation operators. This patch ensures that this holds
true, and makes most of the QUniqueHandle noexcept specifiers valid.

This will make it easier to implement the comparison and relation
operators in terms of the Qt comparison framework.

Task-number: QTBUG-132507
Pick-to: 6.8
Change-Id: Id9fc3fac72a2337541e49c3b4613b8fd082796af
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 49f1877bbbb8f96d81144861558bdcc81e758a58)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Jøger Hansegård 2025-01-03 17:59:42 +01:00 committed by Qt Cherry-pick Bot
parent 55dc2af21d
commit bded4bd5fc

View File

@ -20,6 +20,7 @@
#include <memory>
#include <utility>
#include <type_traits>
QT_BEGIN_NAMESPACE
@ -109,6 +110,19 @@ class QUniqueHandle
{
public:
using Type = typename HandleTraits::Type;
static_assert(std::is_nothrow_default_constructible_v<Type>);
static_assert(std::is_nothrow_constructible_v<Type>);
static_assert(std::is_nothrow_copy_constructible_v<Type>);
static_assert(std::is_nothrow_move_constructible_v<Type>);
static_assert(std::is_nothrow_copy_assignable_v<Type>);
static_assert(std::is_nothrow_move_assignable_v<Type>);
static_assert(std::is_nothrow_destructible_v<Type>);
static_assert(noexcept(std::declval<Type>() == std::declval<Type>()));
static_assert(noexcept(std::declval<Type>() != std::declval<Type>()));
static_assert(noexcept(std::declval<Type>() < std::declval<Type>()));
static_assert(noexcept(std::declval<Type>() <= std::declval<Type>()));
static_assert(noexcept(std::declval<Type>() > std::declval<Type>()));
static_assert(noexcept(std::declval<Type>() >= std::declval<Type>()));
QUniqueHandle() = default;