]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix error copying/move behaviour
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 18 Oct 2022 22:09:55 +0000 (23:09 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 18 Oct 2022 22:09:55 +0000 (23:09 +0100)
src/libutil/cxx/error.hxx

index 65fa76f3b50992b8526bcad727766be384d71e19..714ed309b8e04ae877229c198d0469f70989e342 100644 (file)
@@ -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