From 701af2bebc624b9954f747edca9516bc71608f0d Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Tue, 8 Sep 2020 19:56:54 +0200 Subject: [PATCH] Add noexcept to move constructors and assignment operators --- src/Fd.hpp | 8 ++++---- src/File.hpp | 8 ++++---- src/TemporaryFile.hpp | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Fd.hpp b/src/Fd.hpp index 9cbc1351d..e9d139c13 100644 --- a/src/Fd.hpp +++ b/src/Fd.hpp @@ -27,7 +27,7 @@ class Fd : NonCopyable public: Fd() = default; explicit Fd(int fd); - Fd(Fd&& other_fd); + Fd(Fd&& other_fd) noexcept; ~Fd(); explicit operator bool() const; @@ -35,7 +35,7 @@ public: int get() const; int operator*() const; - Fd& operator=(Fd&& other_fd); + Fd& operator=(Fd&& other_fd) noexcept; // Close wrapped fd before the lifetime of Fd has ended. bool close(); @@ -51,7 +51,7 @@ inline Fd::Fd(int fd) : m_fd(fd) { } -inline Fd::Fd(Fd&& other_fd) : m_fd(other_fd.release()) +inline Fd::Fd(Fd&& other_fd) noexcept : m_fd(other_fd.release()) { } @@ -81,7 +81,7 @@ Fd::operator*() const } inline Fd& -Fd::operator=(Fd&& other_fd) +Fd::operator=(Fd&& other_fd) noexcept { close(); m_fd = other_fd.release(); diff --git a/src/File.hpp b/src/File.hpp index d021dd08f..6f0dd21cd 100644 --- a/src/File.hpp +++ b/src/File.hpp @@ -29,10 +29,10 @@ class File : public NonCopyable public: File() = default; File(const std::string& path, const char* mode); - File(File&& other); + File(File&& other) noexcept; ~File(); - File& operator=(File&& other); + File& operator=(File&& other) noexcept; void open(const std::string& path, const char* mode); void close(); @@ -50,7 +50,7 @@ inline File::File(const std::string& path, const char* mode) open(path, mode); } -inline File::File(File&& other) : m_file(other.m_file) +inline File::File(File&& other) noexcept : m_file(other.m_file) { other.m_file = nullptr; } @@ -61,7 +61,7 @@ inline File::~File() } inline File& -File::operator=(File&& other) +File::operator=(File&& other) noexcept { m_file = other.m_file; other.m_file = nullptr; diff --git a/src/TemporaryFile.hpp b/src/TemporaryFile.hpp index d02eafab5..ca40b4821 100644 --- a/src/TemporaryFile.hpp +++ b/src/TemporaryFile.hpp @@ -32,9 +32,9 @@ public: // the directory will be created if possible.` TemporaryFile(nonstd::string_view path_prefix); - TemporaryFile(TemporaryFile&& other) = default; + TemporaryFile(TemporaryFile&& other) noexcept = default; - TemporaryFile& operator=(TemporaryFile&& other) = default; + TemporaryFile& operator=(TemporaryFile&& other) noexcept = default; // The resulting open file descriptor in read/write mode. Unset on error. Fd fd; -- 2.47.3