Skip to content

Commit

Permalink
clean up noexcept specifiers to adapt to what the implementation prov…
Browse files Browse the repository at this point in the history
…ides
  • Loading branch information
arvidn committed Feb 20, 2018
1 parent 421709f commit 53b4725
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 49 deletions.
3 changes: 1 addition & 2 deletions include/libtorrent/add_torrent_params.hpp
Expand Up @@ -89,8 +89,7 @@ namespace libtorrent {
// data for the torrent. For more information, see the ``storage`` field.
explicit add_torrent_params(storage_constructor_type sc = default_storage_constructor);
add_torrent_params(add_torrent_params&&) noexcept;
// TODO: GCC did not make std::string nothrow move-assignable
add_torrent_params& operator=(add_torrent_params&&);
add_torrent_params& operator=(add_torrent_params&&) = default;
add_torrent_params(add_torrent_params const&);
add_torrent_params& operator=(add_torrent_params const&);

Expand Down
19 changes: 4 additions & 15 deletions include/libtorrent/aux_/noexcept_movable.hpp
Expand Up @@ -44,26 +44,15 @@ namespace aux {
template <typename T>
struct noexcept_movable : T
{
noexcept_movable() noexcept(std::is_nothrow_default_constructible<T>::value) {}
noexcept_movable() = default;
noexcept_movable(noexcept_movable<T>&& rhs) noexcept
: T(std::forward<T>(rhs))
{}
noexcept_movable(noexcept_movable<T> const& rhs)
: T(static_cast<T const&>(rhs))
{}
noexcept_movable(noexcept_movable<T> const& rhs) = default;
noexcept_movable(T&& rhs) noexcept : T(std::forward<T>(rhs)) {} // NOLINT
noexcept_movable(T const& rhs) : T(rhs) {} // NOLINT
noexcept_movable& operator=(noexcept_movable&& rhs) noexcept
{
this->T::operator=(std::forward<T>(rhs));
return *this;
}
noexcept_movable& operator=(noexcept_movable const& rhs)
{
this->T::operator=(rhs);
return *this;
}

noexcept_movable& operator=(noexcept_movable const& rhs) = default;
noexcept_movable& operator=(noexcept_movable&& rhs) = default;
using T::T;
using T::operator=;
};
Expand Down
22 changes: 11 additions & 11 deletions include/libtorrent/bdecode.hpp
Expand Up @@ -258,14 +258,14 @@ struct TORRENT_EXPORT bdecode_node
, error_code& ec, int* error_pos, int depth_limit, int token_limit);

// creates a default constructed node, it will have the type ``none_t``.
bdecode_node();
bdecode_node() = default;

// For owning nodes, the copy will create a copy of the tree, but the
// underlying buffer remains the same.
bdecode_node(bdecode_node const&);
bdecode_node& operator=(bdecode_node const&);
bdecode_node(bdecode_node&&) noexcept;
bdecode_node& operator=(bdecode_node&&) noexcept;
bdecode_node& operator=(bdecode_node&&) = default;

// the types of bdecoded nodes
enum type_t
Expand Down Expand Up @@ -377,25 +377,25 @@ struct TORRENT_EXPORT bdecode_node

// this points to the root nodes token vector
// for the root node, this points to its own m_tokens member
detail::bdecode_token const* m_root_tokens;
detail::bdecode_token const* m_root_tokens = nullptr;

// this points to the original buffer that was parsed
char const* m_buffer;
int m_buffer_size;
char const* m_buffer = nullptr;
int m_buffer_size = 0;

// this is the index into m_root_tokens that this node refers to
// for the root node, it's 0. -1 means uninitialized.
int m_token_idx;
int m_token_idx = -1;

// this is a cache of the last element index looked up. This only applies
// to lists and dictionaries. If the next lookup is at m_last_index or
// greater, we can start iterating the tokens at m_last_token.
mutable int m_last_index;
mutable int m_last_token;
mutable int m_last_index = -1;
mutable int m_last_token = -1;

// the number of elements in this list or dict (computed on the first
// call to dict_size() or list_size())
mutable int m_size;
mutable int m_size = -1;
};

// print the bencoded structure in a human-readable format to a string
Expand Down Expand Up @@ -430,10 +430,10 @@ TORRENT_EXPORT std::string print_entry(bdecode_node const& e
// simply produces references back into it.
TORRENT_EXPORT int bdecode(char const* start, char const* end, bdecode_node& ret
, error_code& ec, int* error_pos = nullptr, int depth_limit = 100
, int token_limit = 1000000);
, int token_limit = 2000000);
TORRENT_EXPORT bdecode_node bdecode(span<char const> buffer
, error_code& ec, int* error_pos = nullptr, int depth_limit = 100
, int token_limit = 1000000);
, int token_limit = 2000000);

}

Expand Down
5 changes: 2 additions & 3 deletions include/libtorrent/file_storage.hpp
Expand Up @@ -45,7 +45,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/string_view.hpp"
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/aux_/noexcept_movable.hpp"
#include "libtorrent/flags.hpp"

namespace libtorrent {
Expand Down Expand Up @@ -211,7 +210,7 @@ namespace libtorrent {
file_storage(file_storage const&);
file_storage& operator=(file_storage const&);
file_storage(file_storage&&) noexcept;
file_storage& operator=(file_storage&&) noexcept;
file_storage& operator=(file_storage&&) = default;

// returns true if the piece length has been initialized
// on the file_storage. This is typically taken as a proxy
Expand Down Expand Up @@ -593,7 +592,7 @@ namespace libtorrent {

// name of torrent. For multi-file torrents
// this is always the root directory
aux::noexcept_movable<std::string> m_name;
std::string m_name;

// the sum of all file sizes
std::int64_t m_total_size;
Expand Down
2 changes: 1 addition & 1 deletion include/libtorrent/torrent_handle.hpp
Expand Up @@ -282,7 +282,7 @@ namespace aux {

// constructs a torrent handle that does not refer to a torrent.
// i.e. is_valid() will return false.
torrent_handle() noexcept {}
torrent_handle() noexcept = default;

torrent_handle(torrent_handle const& t) = default;
torrent_handle(torrent_handle&& t) noexcept = default;
Expand Down
2 changes: 0 additions & 2 deletions include/libtorrent/torrent_status.hpp
Expand Up @@ -58,8 +58,6 @@ namespace libtorrent {
torrent_status(torrent_status const&);
torrent_status& operator=(torrent_status const&);
torrent_status(torrent_status&&) noexcept;
// TODO: 2 msvc and GCC did not make std::string nothrow move-assignable
// until C++17
torrent_status& operator=(torrent_status&&);

// compares if the torrent status objects come from the same torrent. i.e.
Expand Down
1 change: 0 additions & 1 deletion src/add_torrent_params.cpp
Expand Up @@ -37,7 +37,6 @@ namespace libtorrent {
add_torrent_params::add_torrent_params(storage_constructor_type sc)
: storage(std::move(sc)) {}
add_torrent_params::add_torrent_params(add_torrent_params&&) noexcept = default;
add_torrent_params& add_torrent_params::operator=(add_torrent_params&&) = default;
add_torrent_params::add_torrent_params(add_torrent_params const&) = default;
add_torrent_params& add_torrent_params::operator=(add_torrent_params const&) = default;

Expand Down
11 changes: 0 additions & 11 deletions src/bdecode.cpp
Expand Up @@ -202,16 +202,6 @@ namespace {
}
}

bdecode_node::bdecode_node()
: m_root_tokens(nullptr)
, m_buffer(nullptr)
, m_buffer_size(0)
, m_token_idx(-1)
, m_last_index(-1)
, m_last_token(-1)
, m_size(-1)
{}

bdecode_node::bdecode_node(bdecode_node const& n)
: m_tokens(n.m_tokens)
, m_root_tokens(n.m_root_tokens)
Expand Down Expand Up @@ -246,7 +236,6 @@ namespace {
}

bdecode_node::bdecode_node(bdecode_node&&) noexcept = default;
bdecode_node& bdecode_node::operator=(bdecode_node&&) noexcept = default;

bdecode_node::bdecode_node(bdecode_token const* tokens, char const* buf
, int len, int idx)
Expand Down
1 change: 0 additions & 1 deletion src/file_storage.cpp
Expand Up @@ -81,7 +81,6 @@ namespace libtorrent {
file_storage::file_storage(file_storage const&) = default;
file_storage& file_storage::operator=(file_storage const&) = default;
file_storage::file_storage(file_storage&&) noexcept = default;
file_storage& file_storage::operator=(file_storage&&) noexcept = default;

void file_storage::reserve(int num_files)
{
Expand Down
2 changes: 0 additions & 2 deletions src/torrent_status.cpp
Expand Up @@ -49,8 +49,6 @@ namespace libtorrent {

static_assert(std::is_nothrow_move_constructible<torrent_status>::value
, "should be nothrow move constructible");
// static_assert(std::is_nothrow_move_assignable<torrent_status>::value
// , "should be nothrow move assignable");
static_assert(std::is_nothrow_default_constructible<torrent_status>::value
, "should be nothrow default constructible");
}

0 comments on commit 53b4725

Please sign in to comment.