commit 5335bce: [Minor] Fix error copying/move behaviour

Vsevolod Stakhov vsevolod at rspamd.com
Tue Oct 18 22:14:03 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-10-18 23:09:55 +0100
URL: https://github.com/rspamd/rspamd/commit/5335bce593200298976fcd4992dcb14f86f291ed

[Minor] Fix error copying/move behaviour

---
 src/libutil/cxx/error.hxx | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/libutil/cxx/error.hxx b/src/libutil/cxx/error.hxx
index 65fa76f3b..714ed309b 100644
--- a/src/libutil/cxx/error.hxx
+++ b/src/libutil/cxx/error.hxx
@@ -69,6 +69,34 @@ public:
 		error_message = static_storage.value();
 	}
 
+	error(const error &other) : error_code(other.error_code), category(other.category) {
+		if (other.static_storage) {
+			static_storage = other.static_storage;
+			error_message = static_storage.value();
+		}
+		else {
+			error_message = other.error_message;
+		}
+	}
+
+	error(error &&other) noexcept {
+		*this = std::move(other);
+	}
+
+	error& operator = (error &&other) noexcept {
+		if (other.static_storage.has_value()) {
+			std::swap(static_storage, other.static_storage);
+			error_message = static_storage.value();
+		}
+		else {
+			std::swap(error_message, other.error_message);
+		}
+		std::swap(other.error_code, error_code);
+		std::swap(other.category, category);
+
+		return *this;
+	}
+
 	/**
 	 * Convert into GError
 	 * @return


More information about the Commits mailing list