Add missing noexcept specifiers for QUniqueHandle handle traits

Handle traits should be simple, and not require exceptions. This patch
will allow us to improve the noexcept correctness of QUniqueHandle.

Pick-to: 6.8
Change-Id: I84d92818a2fcea5b98e09c0b7dc08b251751396c
Reviewed-by: Tim Blechmann <tim.blechmann@qt.io>
(cherry picked from commit 3c57c7357422bdfda60f56901a7590b258915b6b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Jøger Hansegård 2025-01-03 22:10:34 +01:00 committed by Qt Cherry-pick Bot
parent ee432b6431
commit 8adfacca61
2 changed files with 6 additions and 6 deletions

View File

@ -122,12 +122,12 @@ namespace {
struct DiRegKeyHandleTraits
{
using Type = HKEY;
static Type invalidValue()
static Type invalidValue() noexcept
{
// The setupapi.h functions return INVALID_HANDLE_VALUE when failing to open a registry key
return reinterpret_cast<HKEY>(INVALID_HANDLE_VALUE);
}
static bool close(Type handle) { return RegCloseKey(handle) == ERROR_SUCCESS; }
static bool close(Type handle) noexcept { return RegCloseKey(handle) == ERROR_SUCCESS; }
};
using DiRegKeyHandle = QUniqueHandle<DiRegKeyHandleTraits>;
@ -135,11 +135,11 @@ using DiRegKeyHandle = QUniqueHandle<DiRegKeyHandleTraits>;
struct DevInfoHandleTraits
{
using Type = HDEVINFO;
static Type invalidValue()
static Type invalidValue() noexcept
{
return reinterpret_cast<HDEVINFO>(INVALID_HANDLE_VALUE);
}
static bool close(Type handle) { return SetupDiDestroyDeviceInfoList(handle) == TRUE; }
static bool close(Type handle) noexcept { return SetupDiDestroyDeviceInfoList(handle) == TRUE; }
};
using DevInfoHandle = QUniqueHandle<DevInfoHandleTraits>;

View File

@ -76,7 +76,7 @@ struct TestTraits
{
using Type = GlobalResource::handle;
static bool close(Type handle)
static bool close(Type handle) noexcept
{
return GlobalResource::close(handle);
}
@ -267,7 +267,7 @@ private slots:
{
using Type = int;
static bool close(Type)
static bool close(Type) noexcept
{
return true;
}