From a65d02d3aec7d6b5b2dac07cfc90b59e4dacd4fb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 Aug 2018 16:34:47 +0200 Subject: [PATCH] system/FileDescriptor: add "noexcept" --- src/system/FileDescriptor.cxx | 2 +- src/system/FileDescriptor.hxx | 12 ++++++------ src/system/UniqueFileDescriptor.hxx | 25 +++++++++++++------------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/system/FileDescriptor.cxx b/src/system/FileDescriptor.cxx index e8760f370..920b8d06a 100644 --- a/src/system/FileDescriptor.cxx +++ b/src/system/FileDescriptor.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2017 Max Kellermann + * Copyright 2012-2018 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/system/FileDescriptor.hxx b/src/system/FileDescriptor.hxx index 5e91bbd33..ff42efc32 100644 --- a/src/system/FileDescriptor.hxx +++ b/src/system/FileDescriptor.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2017 Max Kellermann + * Copyright 2012-2018 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -59,13 +59,13 @@ protected: public: FileDescriptor() = default; - explicit constexpr FileDescriptor(int _fd):fd(_fd) {} + explicit constexpr FileDescriptor(int _fd) noexcept:fd(_fd) {} - constexpr bool operator==(FileDescriptor other) const { + constexpr bool operator==(FileDescriptor other) const noexcept { return fd == other.fd; } - constexpr bool IsDefined() const { + constexpr bool IsDefined() const noexcept { return fd >= 0; } @@ -93,7 +93,7 @@ public: * Returns the file descriptor. This may only be called if * IsDefined() returns true. */ - constexpr int Get() const { + constexpr int Get() const noexcept { return fd; } @@ -109,7 +109,7 @@ public: fd = -1; } - static constexpr FileDescriptor Undefined() { + static constexpr FileDescriptor Undefined() noexcept { return FileDescriptor(-1); } diff --git a/src/system/UniqueFileDescriptor.hxx b/src/system/UniqueFileDescriptor.hxx index b6703f7ff..d78e1d0d0 100644 --- a/src/system/UniqueFileDescriptor.hxx +++ b/src/system/UniqueFileDescriptor.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2017 Max Kellermann + * Copyright 2012-2018 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,25 +39,26 @@ */ class UniqueFileDescriptor : protected FileDescriptor { public: - UniqueFileDescriptor():FileDescriptor(FileDescriptor::Undefined()) {} + UniqueFileDescriptor() noexcept + :FileDescriptor(FileDescriptor::Undefined()) {} protected: - explicit UniqueFileDescriptor(int _fd):FileDescriptor(_fd) { + explicit UniqueFileDescriptor(int _fd) noexcept:FileDescriptor(_fd) { assert(IsDefined()); } public: - explicit UniqueFileDescriptor(FileDescriptor _fd) + explicit UniqueFileDescriptor(FileDescriptor _fd) noexcept :FileDescriptor(_fd) {} - UniqueFileDescriptor(UniqueFileDescriptor &&other) + UniqueFileDescriptor(UniqueFileDescriptor &&other) noexcept :FileDescriptor(other.Steal()) {} - ~UniqueFileDescriptor() { + ~UniqueFileDescriptor() noexcept { Close(); } - UniqueFileDescriptor &operator=(UniqueFileDescriptor &&other) { + UniqueFileDescriptor &operator=(UniqueFileDescriptor &&other) noexcept { std::swap(fd, other.fd); return *this; } @@ -65,7 +66,7 @@ public: /** * Convert this object to its #FileDescriptor base type. */ - const FileDescriptor &ToFileDescriptor() const { + const FileDescriptor &ToFileDescriptor() const noexcept { return *this; } @@ -77,7 +78,7 @@ public: using FileDescriptor::Steal; protected: - void Set(int _fd) { + void Set(int _fd) noexcept { assert(!IsDefined()); assert(_fd >= 0); @@ -91,7 +92,7 @@ public: #ifndef _WIN32 using FileDescriptor::OpenNonBlocking; - static bool CreatePipe(UniqueFileDescriptor &r, UniqueFileDescriptor &w) { + static bool CreatePipe(UniqueFileDescriptor &r, UniqueFileDescriptor &w) noexcept { return FileDescriptor::CreatePipe(r, w); } @@ -100,7 +101,7 @@ public: using FileDescriptor::Duplicate; using FileDescriptor::CheckDuplicate; - static bool CreatePipe(FileDescriptor &r, FileDescriptor &w); + static bool CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept; #endif using FileDescriptor::EnableCloseOnExec; @@ -118,7 +119,7 @@ public: using FileDescriptor::CreateInotify; #endif - bool Close() { + bool Close() noexcept { return IsDefined() && FileDescriptor::Close(); }