From bded4bd5fcb319eb1e95f61a3b6bb80f555279a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8ger=20Hanseg=C3=A5rd?= Date: Fri, 3 Jan 2025 17:59:42 +0100 Subject: [PATCH] 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 (cherry picked from commit 49f1877bbbb8f96d81144861558bdcc81e758a58) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/quniquehandle_p.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/corelib/tools/quniquehandle_p.h b/src/corelib/tools/quniquehandle_p.h index d388b1bb0fc..8f9a31a761a 100644 --- a/src/corelib/tools/quniquehandle_p.h +++ b/src/corelib/tools/quniquehandle_p.h @@ -20,6 +20,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -109,6 +110,19 @@ class QUniqueHandle { public: using Type = typename HandleTraits::Type; + static_assert(std::is_nothrow_default_constructible_v); + static_assert(std::is_nothrow_constructible_v); + static_assert(std::is_nothrow_copy_constructible_v); + static_assert(std::is_nothrow_move_constructible_v); + static_assert(std::is_nothrow_copy_assignable_v); + static_assert(std::is_nothrow_move_assignable_v); + static_assert(std::is_nothrow_destructible_v); + static_assert(noexcept(std::declval() == std::declval())); + static_assert(noexcept(std::declval() != std::declval())); + static_assert(noexcept(std::declval() < std::declval())); + static_assert(noexcept(std::declval() <= std::declval())); + static_assert(noexcept(std::declval() > std::declval())); + static_assert(noexcept(std::declval() >= std::declval())); QUniqueHandle() = default;