From 8adfacca6184d439c5febd71a6c78db3edce87c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8ger=20Hanseg=C3=A5rd?= Date: Fri, 3 Jan 2025 22:10:34 +0100 Subject: [PATCH] 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 (cherry picked from commit 3c57c7357422bdfda60f56901a7590b258915b6b) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/windows/qwindowsscreen.cpp | 8 ++++---- .../corelib/tools/quniquehandle/tst_quniquehandle.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 2165c56d3c9..6c86c47caac 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -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(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; @@ -135,11 +135,11 @@ using DiRegKeyHandle = QUniqueHandle; struct DevInfoHandleTraits { using Type = HDEVINFO; - static Type invalidValue() + static Type invalidValue() noexcept { return reinterpret_cast(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; diff --git a/tests/auto/corelib/tools/quniquehandle/tst_quniquehandle.cpp b/tests/auto/corelib/tools/quniquehandle/tst_quniquehandle.cpp index bc8f4685610..55647f3ee4b 100644 --- a/tests/auto/corelib/tools/quniquehandle/tst_quniquehandle.cpp +++ b/tests/auto/corelib/tools/quniquehandle/tst_quniquehandle.cpp @@ -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; }