qualify some assignment operators to disallow assignment to temporaries

This commit is contained in:
arvidn 2018-06-30 18:31:45 +02:00 committed by Arvid Norberg
parent 2c5da2778a
commit d439c8729a
16 changed files with 44 additions and 44 deletions

View File

@ -14,7 +14,7 @@ struct bytes
bytes(std::string&& s): arr(std::move(s)) {} bytes(std::string&& s): arr(std::move(s)) {}
bytes(bytes const&) = default; bytes(bytes const&) = default;
bytes(bytes&&) noexcept = default; bytes(bytes&&) noexcept = default;
bytes& operator=(bytes&&) noexcept = default; bytes& operator=(bytes&&) & noexcept = default;
bytes() {} bytes() {}
std::string arr; std::string arr;
}; };

View File

@ -72,7 +72,7 @@ namespace libtorrent { namespace aux {
crypt_hash(crypt_hash const& h) { m_hash = duplicate(h); } crypt_hash(crypt_hash const& h) { m_hash = duplicate(h); }
~crypt_hash() { CryptDestroyHash(m_hash); } ~crypt_hash() { CryptDestroyHash(m_hash); }
crypt_hash& crypt_hash::operator=(crypt_hash const& h) crypt_hash& crypt_hash::operator=(crypt_hash const& h) &
{ {
if (this == &h) return *this; if (this == &h) return *this;
HCRYPTHASH temp = duplicate(h); HCRYPTHASH temp = duplicate(h);

View File

@ -86,7 +86,7 @@ namespace libtorrent {
used_size = rhs.used_size; used_size = rhs.used_size;
move_holder(&holder, &rhs.holder); move_holder(&holder, &rhs.holder);
} }
buffer_t& operator=(buffer_t&& rhs) noexcept buffer_t& operator=(buffer_t&& rhs) & noexcept
{ {
destruct_holder(&holder); destruct_holder(&holder);
destruct_holder = rhs.destruct_holder; destruct_holder = rhs.destruct_holder;
@ -99,7 +99,7 @@ namespace libtorrent {
} }
buffer_t(buffer_t const& rhs) noexcept buffer_t(buffer_t const& rhs) noexcept
: buffer_t(std::move(const_cast<buffer_t&>(rhs))) {} : buffer_t(std::move(const_cast<buffer_t&>(rhs))) {}
buffer_t& operator=(buffer_t const& rhs) noexcept buffer_t& operator=(buffer_t const& rhs) & noexcept
{ return this->operator=(std::move(const_cast<buffer_t&>(rhs))); } { return this->operator=(std::move(const_cast<buffer_t&>(rhs))); }
#else #else
buffer_t(buffer_t&&) = delete; buffer_t(buffer_t&&) = delete;

View File

@ -46,13 +46,13 @@ namespace libtorrent {
copy_ptr(copy_ptr&& p) noexcept = default; copy_ptr(copy_ptr&& p) noexcept = default;
void reset(T* t = nullptr) { m_ptr.reset(t); } void reset(T* t = nullptr) { m_ptr.reset(t); }
copy_ptr& operator=(copy_ptr const& p) copy_ptr& operator=(copy_ptr const& p) &
{ {
if (m_ptr == p.m_ptr) return *this; if (m_ptr == p.m_ptr) return *this;
m_ptr.reset(p.m_ptr ? new T(*p.m_ptr) : nullptr); m_ptr.reset(p.m_ptr ? new T(*p.m_ptr) : nullptr);
return *this; return *this;
} }
copy_ptr& operator=(copy_ptr&& p) noexcept = default; copy_ptr& operator=(copy_ptr&& p) & noexcept = default;
T* operator->() { return m_ptr.get(); } T* operator->() { return m_ptr.get(); }
T const* operator->() const { return m_ptr.get(); } T const* operator->() const { return m_ptr.get(); }
T& operator*() { return *m_ptr; } T& operator*() { return *m_ptr; }

View File

@ -60,7 +60,7 @@ namespace libtorrent {
disk_buffer_holder(buffer_allocator_interface& alloc disk_buffer_holder(buffer_allocator_interface& alloc
, char* buf, std::size_t sz) noexcept; , char* buf, std::size_t sz) noexcept;
disk_buffer_holder& operator=(disk_buffer_holder&&) noexcept; disk_buffer_holder& operator=(disk_buffer_holder&&) & noexcept;
disk_buffer_holder(disk_buffer_holder&&) noexcept; disk_buffer_holder(disk_buffer_holder&&) noexcept;
disk_buffer_holder& operator=(disk_buffer_holder const&) = delete; disk_buffer_holder& operator=(disk_buffer_holder const&) = delete;

View File

@ -191,17 +191,17 @@ namespace aux {
// copies the structure of the right hand side into this // copies the structure of the right hand side into this
// entry. // entry.
#if TORRENT_ABI_VERSION == 1 #if TORRENT_ABI_VERSION == 1
entry& operator=(lazy_entry const&); entry& operator=(lazy_entry const&) &;
#endif #endif
entry& operator=(bdecode_node const&); entry& operator=(bdecode_node const&) &;
entry& operator=(entry const&); entry& operator=(entry const&) &;
entry& operator=(entry&&) noexcept; entry& operator=(entry&&) & noexcept;
entry& operator=(dictionary_type); entry& operator=(dictionary_type) &;
entry& operator=(span<char const>); entry& operator=(span<char const>) &;
template <typename U, typename Cond = typename std::enable_if< template <typename U, typename Cond = typename std::enable_if<
std::is_same<U, entry::string_type>::value std::is_same<U, entry::string_type>::value
|| std::is_same<U, char const*>::value>::type> || std::is_same<U, char const*>::value>::type>
entry& operator=(U v) entry& operator=(U v) &
{ {
destruct(); destruct();
new(&data) string_type(std::move(v)); new(&data) string_type(std::move(v));
@ -211,9 +211,9 @@ namespace aux {
#endif #endif
return *this; return *this;
} }
entry& operator=(list_type); entry& operator=(list_type) &;
entry& operator=(integer_type); entry& operator=(integer_type) &;
entry& operator=(preformatted_type); entry& operator=(preformatted_type) &;
// The ``integer()``, ``string()``, ``list()`` and ``dict()`` functions // The ``integer()``, ``string()``, ``list()`` and ``dict()`` functions
// are accessors that return the respective type. If the ``entry`` object // are accessors that return the respective type. If the ``entry`` object

View File

@ -59,9 +59,9 @@ namespace libtorrent {
// hidden // hidden
~file_entry(); ~file_entry();
file_entry(file_entry const&) = default; file_entry(file_entry const&) = default;
file_entry& operator=(file_entry const&) = default; file_entry& operator=(file_entry const&) & = default;
file_entry(file_entry&&) noexcept = default; file_entry(file_entry&&) noexcept = default;
file_entry& operator=(file_entry&&) noexcept = default; file_entry& operator=(file_entry&&) & noexcept = default;
// the full path of this file. The paths are unicode strings // the full path of this file. The paths are unicode strings
// encoded in UTF-8. // encoded in UTF-8.
@ -117,9 +117,9 @@ namespace libtorrent {
internal_file_entry(); internal_file_entry();
internal_file_entry(internal_file_entry const& fe); internal_file_entry(internal_file_entry const& fe);
internal_file_entry& operator=(internal_file_entry const& fe); internal_file_entry& operator=(internal_file_entry const& fe) &;
internal_file_entry(internal_file_entry&& fe) noexcept; internal_file_entry(internal_file_entry&& fe) noexcept;
internal_file_entry& operator=(internal_file_entry&& fe) noexcept; internal_file_entry& operator=(internal_file_entry&& fe) & noexcept;
~internal_file_entry(); ~internal_file_entry();
void set_name(char const* n, bool borrow_string = false, int string_len = 0); void set_name(char const* n, bool borrow_string = false, int string_len = 0);

View File

@ -90,7 +90,7 @@ namespace libtorrent {
hasher(char const* data, int len); hasher(char const* data, int len);
explicit hasher(span<char const> data); explicit hasher(span<char const> data);
hasher(hasher const&); hasher(hasher const&);
hasher& operator=(hasher const&); hasher& operator=(hasher const&) &;
// append the following bytes to what is being hashed // append the following bytes to what is being hashed
hasher& update(span<char const> data); hasher& update(span<char const> data);

View File

@ -91,7 +91,7 @@ namespace libtorrent {
// ``update(data)``. // ``update(data)``.
explicit hasher512(span<char const> data); explicit hasher512(span<char const> data);
hasher512(hasher512 const&); hasher512(hasher512 const&);
hasher512& operator=(hasher512 const&); hasher512& operator=(hasher512 const&) &;
// append the following bytes to what is being hashed // append the following bytes to what is being hashed
hasher512& update(span<char const> data); hasher512& update(span<char const> data);

View File

@ -44,7 +44,7 @@ TORRENT_IPV6_NAMESPACE
{ {
union_address() { *this = address(); } union_address() { *this = address(); }
explicit union_address(address const& a) { *this = a; } explicit union_address(address const& a) { *this = a; }
union_address& operator=(address const& a) union_address& operator=(address const& a) &
{ {
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
v4 = a.is_v4(); v4 = a.is_v4();
@ -104,7 +104,7 @@ TORRENT_IPV6_NAMESPACE
explicit union_endpoint(udp::endpoint const& ep) { *this = ep; } explicit union_endpoint(udp::endpoint const& ep) { *this = ep; }
union_endpoint() { *this = tcp::endpoint(); } union_endpoint() { *this = tcp::endpoint(); }
union_endpoint& operator=(udp::endpoint const& ep) union_endpoint& operator=(udp::endpoint const& ep) &
{ {
addr = ep.address(); addr = ep.address();
port = ep.port(); port = ep.port();
@ -113,7 +113,7 @@ TORRENT_IPV6_NAMESPACE
operator udp::endpoint() const { return udp::endpoint(addr, port); } operator udp::endpoint() const { return udp::endpoint(addr, port); }
union_endpoint& operator=(tcp::endpoint const& ep) union_endpoint& operator=(tcp::endpoint const& ep) &
{ {
addr = ep.address(); addr = ep.address();
port = ep.port(); port = ep.port();

View File

@ -88,8 +88,8 @@ namespace libtorrent { namespace aux {
strong_typedef& operator-=(diff_type rhs) strong_typedef& operator-=(diff_type rhs)
{ m_val -= static_cast<UnderlyingType>(rhs); return *this; } { m_val -= static_cast<UnderlyingType>(rhs); return *this; }
strong_typedef& operator=(strong_typedef const& rhs) noexcept = default; strong_typedef& operator=(strong_typedef const& rhs) & noexcept = default;
strong_typedef& operator=(strong_typedef&& rhs) noexcept = default; strong_typedef& operator=(strong_typedef&& rhs) & noexcept = default;
private: private:
UnderlyingType m_val; UnderlyingType m_val;
}; };

View File

@ -39,7 +39,7 @@ namespace libtorrent {
: m_allocator(&alloc), m_buf(buf), m_size(sz), m_ref() : m_allocator(&alloc), m_buf(buf), m_size(sz), m_ref()
{} {}
disk_buffer_holder& disk_buffer_holder::operator=(disk_buffer_holder&& h) noexcept disk_buffer_holder& disk_buffer_holder::operator=(disk_buffer_holder&& h) & noexcept
{ {
if (&h == this) return *this; if (&h == this) return *this;
disk_buffer_holder(std::move(h)).swap(*this); disk_buffer_holder(std::move(h)).swap(*this);

View File

@ -132,7 +132,7 @@ namespace {
entry::~entry() { destruct(); } entry::~entry() { destruct(); }
entry& entry::operator=(const entry& e) entry& entry::operator=(const entry& e) &
{ {
if (&e == this) return *this; if (&e == this) return *this;
destruct(); destruct();
@ -140,7 +140,7 @@ namespace {
return *this; return *this;
} }
entry& entry::operator=(entry&& e) noexcept entry& entry::operator=(entry&& e) & noexcept
{ {
if (&e == this) return *this; if (&e == this) return *this;
destruct(); destruct();
@ -360,7 +360,7 @@ namespace {
} }
// convert a bdecode_node into an old skool entry // convert a bdecode_node into an old skool entry
entry& entry::operator=(bdecode_node const& e) entry& entry::operator=(bdecode_node const& e) &
{ {
switch (e.type()) switch (e.type())
{ {
@ -399,7 +399,7 @@ namespace {
#if TORRENT_ABI_VERSION == 1 #if TORRENT_ABI_VERSION == 1
// convert a lazy_entry into an old skool entry // convert a lazy_entry into an old skool entry
entry& entry::operator=(lazy_entry const& e) entry& entry::operator=(lazy_entry const& e) &
{ {
switch (e.type()) switch (e.type())
{ {
@ -437,7 +437,7 @@ namespace {
} }
#endif #endif
entry& entry::operator=(preformatted_type v) entry& entry::operator=(preformatted_type v) &
{ {
destruct(); destruct();
new(&data) preformatted_type(std::move(v)); new(&data) preformatted_type(std::move(v));
@ -448,7 +448,7 @@ namespace {
return *this; return *this;
} }
entry& entry::operator=(dictionary_type v) entry& entry::operator=(dictionary_type v) &
{ {
destruct(); destruct();
new(&data) dictionary_type(std::move(v)); new(&data) dictionary_type(std::move(v));
@ -459,7 +459,7 @@ namespace {
return *this; return *this;
} }
entry& entry::operator=(span<char const> v) entry& entry::operator=(span<char const> v) &
{ {
destruct(); destruct();
new(&data) string_type(v.data(), v.size()); new(&data) string_type(v.data(), v.size());
@ -470,7 +470,7 @@ namespace {
return *this; return *this;
} }
entry& entry::operator=(list_type v) entry& entry::operator=(list_type v) &
{ {
destruct(); destruct();
new(&data) list_type(std::move(v)); new(&data) list_type(std::move(v));
@ -481,7 +481,7 @@ namespace {
return *this; return *this;
} }
entry& entry::operator=(integer_type v) entry& entry::operator=(integer_type v) &
{ {
destruct(); destruct();
new(&data) integer_type(std::move(v)); new(&data) integer_type(std::move(v));

View File

@ -241,7 +241,7 @@ namespace {
name = fe.name; name = fe.name;
} }
internal_file_entry& internal_file_entry::operator=(internal_file_entry const& fe) internal_file_entry& internal_file_entry::operator=(internal_file_entry const& fe) &
{ {
if (&fe == this) return *this; if (&fe == this) return *this;
offset = fe.offset; offset = fe.offset;
@ -274,7 +274,7 @@ namespace {
fe.name = nullptr; fe.name = nullptr;
} }
internal_file_entry& internal_file_entry::operator=(internal_file_entry&& fe) noexcept internal_file_entry& internal_file_entry::operator=(internal_file_entry&& fe) & noexcept
{ {
if (&fe == this) return *this; if (&fe == this) return *this;
offset = fe.offset; offset = fe.offset;

View File

@ -75,7 +75,7 @@ namespace libtorrent {
gcry_md_copy(&m_context, h.m_context); gcry_md_copy(&m_context, h.m_context);
} }
hasher& hasher::operator=(hasher const& h) hasher& hasher::operator=(hasher const& h) &
{ {
if (this == &h) return; if (this == &h) return;
gcry_md_close(m_context); gcry_md_close(m_context);
@ -84,7 +84,7 @@ namespace libtorrent {
} }
#else #else
hasher::hasher(hasher const&) = default; hasher::hasher(hasher const&) = default;
hasher& hasher::operator=(hasher const&) = default; hasher& hasher::operator=(hasher const&) & = default;
#endif #endif
hasher& hasher::update(char const* data, int len) hasher& hasher::update(char const* data, int len)

View File

@ -68,7 +68,7 @@ namespace libtorrent {
gcry_md_copy(&m_context, h.m_context); gcry_md_copy(&m_context, h.m_context);
} }
hasher512& hasher512::operator=(hasher512 const& h) hasher512& hasher512::operator=(hasher512 const& h) &
{ {
if (this == &h) return; if (this == &h) return;
gcry_md_close(m_context); gcry_md_close(m_context);
@ -77,7 +77,7 @@ namespace libtorrent {
} }
#else #else
hasher512::hasher512(hasher512 const&) = default; hasher512::hasher512(hasher512 const&) = default;
hasher512& hasher512::operator=(hasher512 const&) = default; hasher512& hasher512::operator=(hasher512 const&) & = default;
#endif #endif
hasher512& hasher512::update(span<char const> data) hasher512& hasher512::update(span<char const> data)