From d439c8729ae268841296be22031aa640c0b5b53d Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 30 Jun 2018 18:31:45 +0200 Subject: [PATCH] qualify some assignment operators to disallow assignment to temporaries --- bindings/python/src/bytes.hpp | 2 +- .../libtorrent/aux_/win_crypto_provider.hpp | 2 +- include/libtorrent/chained_buffer.hpp | 4 ++-- include/libtorrent/copy_ptr.hpp | 4 ++-- include/libtorrent/disk_buffer_holder.hpp | 2 +- include/libtorrent/entry.hpp | 20 +++++++++---------- include/libtorrent/file_storage.hpp | 8 ++++---- include/libtorrent/hasher.hpp | 2 +- include/libtorrent/hasher512.hpp | 2 +- include/libtorrent/union_endpoint.hpp | 6 +++--- include/libtorrent/units.hpp | 4 ++-- src/disk_buffer_holder.cpp | 2 +- src/entry.cpp | 18 ++++++++--------- src/file_storage.cpp | 4 ++-- src/hasher.cpp | 4 ++-- src/hasher512.cpp | 4 ++-- 16 files changed, 44 insertions(+), 44 deletions(-) diff --git a/bindings/python/src/bytes.hpp b/bindings/python/src/bytes.hpp index 245583181..64ce4232a 100644 --- a/bindings/python/src/bytes.hpp +++ b/bindings/python/src/bytes.hpp @@ -14,7 +14,7 @@ struct bytes bytes(std::string&& s): arr(std::move(s)) {} bytes(bytes const&) = default; bytes(bytes&&) noexcept = default; - bytes& operator=(bytes&&) noexcept = default; + bytes& operator=(bytes&&) & noexcept = default; bytes() {} std::string arr; }; diff --git a/include/libtorrent/aux_/win_crypto_provider.hpp b/include/libtorrent/aux_/win_crypto_provider.hpp index f522eda04..4ad67103e 100644 --- a/include/libtorrent/aux_/win_crypto_provider.hpp +++ b/include/libtorrent/aux_/win_crypto_provider.hpp @@ -72,7 +72,7 @@ namespace libtorrent { namespace aux { crypt_hash(crypt_hash const& h) { m_hash = duplicate(h); } ~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; HCRYPTHASH temp = duplicate(h); diff --git a/include/libtorrent/chained_buffer.hpp b/include/libtorrent/chained_buffer.hpp index bfb31ccb4..a308cf717 100644 --- a/include/libtorrent/chained_buffer.hpp +++ b/include/libtorrent/chained_buffer.hpp @@ -86,7 +86,7 @@ namespace libtorrent { used_size = rhs.used_size; move_holder(&holder, &rhs.holder); } - buffer_t& operator=(buffer_t&& rhs) noexcept + buffer_t& operator=(buffer_t&& rhs) & noexcept { destruct_holder(&holder); destruct_holder = rhs.destruct_holder; @@ -99,7 +99,7 @@ namespace libtorrent { } buffer_t(buffer_t const& rhs) noexcept : buffer_t(std::move(const_cast(rhs))) {} - buffer_t& operator=(buffer_t const& rhs) noexcept + buffer_t& operator=(buffer_t const& rhs) & noexcept { return this->operator=(std::move(const_cast(rhs))); } #else buffer_t(buffer_t&&) = delete; diff --git a/include/libtorrent/copy_ptr.hpp b/include/libtorrent/copy_ptr.hpp index 9b7a6ca31..e18f2f073 100644 --- a/include/libtorrent/copy_ptr.hpp +++ b/include/libtorrent/copy_ptr.hpp @@ -46,13 +46,13 @@ namespace libtorrent { copy_ptr(copy_ptr&& p) noexcept = default; 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; m_ptr.reset(p.m_ptr ? new T(*p.m_ptr) : nullptr); 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 const* operator->() const { return m_ptr.get(); } T& operator*() { return *m_ptr; } diff --git a/include/libtorrent/disk_buffer_holder.hpp b/include/libtorrent/disk_buffer_holder.hpp index b34a51ba6..42c630c79 100644 --- a/include/libtorrent/disk_buffer_holder.hpp +++ b/include/libtorrent/disk_buffer_holder.hpp @@ -60,7 +60,7 @@ namespace libtorrent { disk_buffer_holder(buffer_allocator_interface& alloc , 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& operator=(disk_buffer_holder const&) = delete; diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index a4cec458c..49fb18e62 100644 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -191,17 +191,17 @@ namespace aux { // copies the structure of the right hand side into this // entry. #if TORRENT_ABI_VERSION == 1 - entry& operator=(lazy_entry const&); + entry& operator=(lazy_entry const&) &; #endif - entry& operator=(bdecode_node const&); - entry& operator=(entry const&); - entry& operator=(entry&&) noexcept; - entry& operator=(dictionary_type); - entry& operator=(span); + entry& operator=(bdecode_node const&) &; + entry& operator=(entry const&) &; + entry& operator=(entry&&) & noexcept; + entry& operator=(dictionary_type) &; + entry& operator=(span) &; template ::value || std::is_same::value>::type> - entry& operator=(U v) + entry& operator=(U v) & { destruct(); new(&data) string_type(std::move(v)); @@ -211,9 +211,9 @@ namespace aux { #endif return *this; } - entry& operator=(list_type); - entry& operator=(integer_type); - entry& operator=(preformatted_type); + entry& operator=(list_type) &; + entry& operator=(integer_type) &; + entry& operator=(preformatted_type) &; // The ``integer()``, ``string()``, ``list()`` and ``dict()`` functions // are accessors that return the respective type. If the ``entry`` object diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index d64fff47c..75097db76 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -59,9 +59,9 @@ namespace libtorrent { // hidden ~file_entry(); 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& operator=(file_entry&&) noexcept = default; + file_entry& operator=(file_entry&&) & noexcept = default; // the full path of this file. The paths are unicode strings // encoded in UTF-8. @@ -117,9 +117,9 @@ namespace libtorrent { internal_file_entry(); 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& operator=(internal_file_entry&& fe) noexcept; + internal_file_entry& operator=(internal_file_entry&& fe) & noexcept; ~internal_file_entry(); void set_name(char const* n, bool borrow_string = false, int string_len = 0); diff --git a/include/libtorrent/hasher.hpp b/include/libtorrent/hasher.hpp index 3d6af004e..343695148 100644 --- a/include/libtorrent/hasher.hpp +++ b/include/libtorrent/hasher.hpp @@ -90,7 +90,7 @@ namespace libtorrent { hasher(char const* data, int len); explicit hasher(span data); hasher(hasher const&); - hasher& operator=(hasher const&); + hasher& operator=(hasher const&) &; // append the following bytes to what is being hashed hasher& update(span data); diff --git a/include/libtorrent/hasher512.hpp b/include/libtorrent/hasher512.hpp index 2bec938f7..e8fb0df36 100644 --- a/include/libtorrent/hasher512.hpp +++ b/include/libtorrent/hasher512.hpp @@ -91,7 +91,7 @@ namespace libtorrent { // ``update(data)``. explicit hasher512(span data); hasher512(hasher512 const&); - hasher512& operator=(hasher512 const&); + hasher512& operator=(hasher512 const&) &; // append the following bytes to what is being hashed hasher512& update(span data); diff --git a/include/libtorrent/union_endpoint.hpp b/include/libtorrent/union_endpoint.hpp index 7488faabd..b7fc7ab6e 100644 --- a/include/libtorrent/union_endpoint.hpp +++ b/include/libtorrent/union_endpoint.hpp @@ -44,7 +44,7 @@ TORRENT_IPV6_NAMESPACE { union_address() { *this = address(); } explicit union_address(address const& a) { *this = a; } - union_address& operator=(address const& a) + union_address& operator=(address const& a) & { #if TORRENT_USE_IPV6 v4 = a.is_v4(); @@ -104,7 +104,7 @@ TORRENT_IPV6_NAMESPACE explicit union_endpoint(udp::endpoint const& ep) { *this = ep; } union_endpoint() { *this = tcp::endpoint(); } - union_endpoint& operator=(udp::endpoint const& ep) + union_endpoint& operator=(udp::endpoint const& ep) & { addr = ep.address(); port = ep.port(); @@ -113,7 +113,7 @@ TORRENT_IPV6_NAMESPACE 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(); port = ep.port(); diff --git a/include/libtorrent/units.hpp b/include/libtorrent/units.hpp index b9bbf4a28..65dcd77a3 100644 --- a/include/libtorrent/units.hpp +++ b/include/libtorrent/units.hpp @@ -88,8 +88,8 @@ namespace libtorrent { namespace aux { strong_typedef& operator-=(diff_type rhs) { m_val -= static_cast(rhs); return *this; } - strong_typedef& operator=(strong_typedef const& rhs) noexcept = default; - strong_typedef& operator=(strong_typedef&& rhs) noexcept = default; + strong_typedef& operator=(strong_typedef const& rhs) & noexcept = default; + strong_typedef& operator=(strong_typedef&& rhs) & noexcept = default; private: UnderlyingType m_val; }; diff --git a/src/disk_buffer_holder.cpp b/src/disk_buffer_holder.cpp index c6715c676..e2ad68854 100644 --- a/src/disk_buffer_holder.cpp +++ b/src/disk_buffer_holder.cpp @@ -39,7 +39,7 @@ namespace libtorrent { : 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; disk_buffer_holder(std::move(h)).swap(*this); diff --git a/src/entry.cpp b/src/entry.cpp index f50511b13..7a04d9fe9 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -132,7 +132,7 @@ namespace { entry::~entry() { destruct(); } - entry& entry::operator=(const entry& e) + entry& entry::operator=(const entry& e) & { if (&e == this) return *this; destruct(); @@ -140,7 +140,7 @@ namespace { return *this; } - entry& entry::operator=(entry&& e) noexcept + entry& entry::operator=(entry&& e) & noexcept { if (&e == this) return *this; destruct(); @@ -360,7 +360,7 @@ namespace { } // 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()) { @@ -399,7 +399,7 @@ namespace { #if TORRENT_ABI_VERSION == 1 // 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()) { @@ -437,7 +437,7 @@ namespace { } #endif - entry& entry::operator=(preformatted_type v) + entry& entry::operator=(preformatted_type v) & { destruct(); new(&data) preformatted_type(std::move(v)); @@ -448,7 +448,7 @@ namespace { return *this; } - entry& entry::operator=(dictionary_type v) + entry& entry::operator=(dictionary_type v) & { destruct(); new(&data) dictionary_type(std::move(v)); @@ -459,7 +459,7 @@ namespace { return *this; } - entry& entry::operator=(span v) + entry& entry::operator=(span v) & { destruct(); new(&data) string_type(v.data(), v.size()); @@ -470,7 +470,7 @@ namespace { return *this; } - entry& entry::operator=(list_type v) + entry& entry::operator=(list_type v) & { destruct(); new(&data) list_type(std::move(v)); @@ -481,7 +481,7 @@ namespace { return *this; } - entry& entry::operator=(integer_type v) + entry& entry::operator=(integer_type v) & { destruct(); new(&data) integer_type(std::move(v)); diff --git a/src/file_storage.cpp b/src/file_storage.cpp index f41656240..4c536abea 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -241,7 +241,7 @@ namespace { 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; offset = fe.offset; @@ -274,7 +274,7 @@ namespace { 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; offset = fe.offset; diff --git a/src/hasher.cpp b/src/hasher.cpp index f0d04912a..24bfdf7c7 100644 --- a/src/hasher.cpp +++ b/src/hasher.cpp @@ -75,7 +75,7 @@ namespace libtorrent { gcry_md_copy(&m_context, h.m_context); } - hasher& hasher::operator=(hasher const& h) + hasher& hasher::operator=(hasher const& h) & { if (this == &h) return; gcry_md_close(m_context); @@ -84,7 +84,7 @@ namespace libtorrent { } #else hasher::hasher(hasher const&) = default; - hasher& hasher::operator=(hasher const&) = default; + hasher& hasher::operator=(hasher const&) & = default; #endif hasher& hasher::update(char const* data, int len) diff --git a/src/hasher512.cpp b/src/hasher512.cpp index b5e80f4b0..9f4b96614 100644 --- a/src/hasher512.cpp +++ b/src/hasher512.cpp @@ -68,7 +68,7 @@ namespace libtorrent { gcry_md_copy(&m_context, h.m_context); } - hasher512& hasher512::operator=(hasher512 const& h) + hasher512& hasher512::operator=(hasher512 const& h) & { if (this == &h) return; gcry_md_close(m_context); @@ -77,7 +77,7 @@ namespace libtorrent { } #else hasher512::hasher512(hasher512 const&) = default; - hasher512& hasher512::operator=(hasher512 const&) = default; + hasher512& hasher512::operator=(hasher512 const&) & = default; #endif hasher512& hasher512::update(span data)