From fac9931eb6b34b5a66fedba45c4c984fb40d22ff Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 4 Jan 2018 21:02:34 +0100 Subject: [PATCH] fix noexcept marking on entry, and make move assignment --- include/libtorrent/aux_/noexcept_movable.hpp | 4 ++- include/libtorrent/entry.hpp | 2 +- src/entry.cpp | 37 +++++++++++++++----- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/include/libtorrent/aux_/noexcept_movable.hpp b/include/libtorrent/aux_/noexcept_movable.hpp index 28715ebde..283990c8d 100644 --- a/include/libtorrent/aux_/noexcept_movable.hpp +++ b/include/libtorrent/aux_/noexcept_movable.hpp @@ -32,6 +32,8 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_NOEXCEPT_MOVABLE_HPP_INCLUDED #define TORRENT_NOEXCEPT_MOVABLE_HPP_INCLUDED +#include + namespace libtorrent { namespace aux { @@ -42,7 +44,7 @@ namespace aux { template struct noexcept_movable : T { - noexcept_movable() noexcept {} + noexcept_movable() noexcept(std::is_nothrow_default_constructible::value) {} noexcept_movable(noexcept_movable&& rhs) noexcept : T(std::forward(rhs)) {} diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index a0b45b424..1ead27943 100644 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -274,7 +274,7 @@ namespace aux { const preformatted_type& preformatted() const; // swaps the content of *this* with ``e``. - void swap(entry& e) noexcept; + void swap(entry& e); // All of these functions requires the entry to be a dictionary, if it // isn't they will throw ``system_error``. diff --git a/src/entry.cpp b/src/entry.cpp index 878f578a5..7edea630f 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -143,7 +143,32 @@ namespace { entry& entry::operator=(entry&& e) noexcept { if (&e == this) return *this; - swap(e); + destruct(); + const auto t = e.type(); + switch (t) + { + case int_t: + new (&data) integer_type(std::move(e.integer())); + break; + case string_t: + new (&data) string_type(std::move(e.string())); + break; + case list_t: + new (&data) list_type(std::move(e.list())); + break; + case dictionary_t: + new (&data) dictionary_type(std::move(e.dict())); + break; + case undefined_t: + break; + case preformatted_t: + new (&data) preformatted_type(std::move(e.preformatted())); + break; + } + m_type = t; +#if TORRENT_USE_ASSERTS + m_type_queried = true; +#endif return *this; } @@ -281,13 +306,7 @@ namespace { entry::entry(entry&& e) noexcept : m_type(undefined_t) { -#if TORRENT_USE_ASSERTS - uint8_t type_queried = e.m_type_queried; -#endif - swap(e); -#if TORRENT_USE_ASSERTS - m_type_queried = type_queried; -#endif + this->operator=(std::move(e)); } entry::entry(dictionary_type v) @@ -581,7 +600,7 @@ namespace { #endif } - void entry::swap(entry& e) noexcept + void entry::swap(entry& e) { bool clear_this = false; bool clear_that = false;