From a80d1bf2716b1ba404799d6a09003b145b73b079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8ger=20Hanseg=C3=A5rd?= Date: Sat, 4 Jan 2025 20:08:17 +0100 Subject: [PATCH] Add missing noexcept specifiers for QUniqueHandle handle traits Handle traits should be simple, and not require exceptions. Note that we should not make calls to fclose() or close() noexcept, because these are POSIX cancellation points. Pick-to: 6.8 6.9 Change-Id: I8bbf573b1346eafd52c6080dbb024f8b3bc89359 Reviewed-by: Thiago Macieira --- src/corelib/tools/quniquehandle_types.cpp | 6 ++++-- src/corelib/tools/quniquehandle_types_p.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/quniquehandle_types.cpp b/src/corelib/tools/quniquehandle_types.cpp index 59b9ebe179c..a46006ab6f3 100644 --- a/src/corelib/tools/quniquehandle_types.cpp +++ b/src/corelib/tools/quniquehandle_types.cpp @@ -19,12 +19,12 @@ namespace QtUniqueHandleTraits { #ifdef Q_OS_WIN -bool InvalidHandleTraits::close(Type handle) +bool InvalidHandleTraits::close(Type handle) noexcept { return ::CloseHandle(handle); } -bool NullHandleTraits::close(Type handle) +bool NullHandleTraits::close(Type handle) noexcept { return ::CloseHandle(handle); } @@ -33,11 +33,13 @@ bool NullHandleTraits::close(Type handle) bool FileDescriptorHandleTraits::close(Type handle) { + // not noexcept because close() is a POSIX cancellation point return QT_CLOSE(handle) == 0; } bool FILEHandleTraits::close(Type handle) { + // not noexcept because fclose() is a POSIX cancellation point return ::fclose(handle); } diff --git a/src/corelib/tools/quniquehandle_types_p.h b/src/corelib/tools/quniquehandle_types_p.h index 01bcfd76bba..59dacb1cf09 100644 --- a/src/corelib/tools/quniquehandle_types_p.h +++ b/src/corelib/tools/quniquehandle_types_p.h @@ -33,14 +33,14 @@ struct InvalidHandleTraits { return Qt::HANDLE(-1); // AKA INVALID_HANDLE_VALUE } - Q_CORE_EXPORT static bool close(Type handle); + Q_CORE_EXPORT static bool close(Type handle) noexcept; }; struct NullHandleTraits { using Type = Qt::HANDLE; static Type invalidValue() noexcept { return nullptr; } - Q_CORE_EXPORT static bool close(Type handle); + Q_CORE_EXPORT static bool close(Type handle) noexcept; }; #endif