be a bit more strict about when the STL containers need complete types (to make it build under GCC with concept checks enabled). add proper assignment operator to types used in STL containers

This commit is contained in:
arvidn 2016-02-20 23:40:45 -05:00
parent c28789260d
commit 3f3b366ed5
9 changed files with 67 additions and 37 deletions

View File

@ -96,6 +96,10 @@ POSSIBILITY OF SUCH DAMAGE.
#if defined __GNUC__
#ifdef _GLIBCXX_CONCEPT_CHECKS
#define TORRENT_COMPLETE_TYPES_REQUIRED 1
#endif
// deprecation markup is only enabled when libtorrent
// headers are included by clients, not while building
// libtorrent itself
@ -112,6 +116,8 @@ POSSIBILITY OF SUCH DAMAGE.
// seem to allow boost::array in unions
#define TORRENT_BROKEN_UNIONS 1
#define TORRENT_COMPLETE_TYPES_REQUIRED 1
// ======= MSVC =========
#elif defined BOOST_MSVC
@ -124,6 +130,10 @@ POSSIBILITY OF SUCH DAMAGE.
// '_vsnprintf': This function or variable may be unsafe
#pragma warning(disable:4996)
#if (defined(_MSC_VER) && _MSC_VER < 1310)
#define TORRENT_COMPLETE_TYPES_REQUIRED 1
#endif
// deprecation markup is only enabled when libtorrent
// headers are included by clients, not while building
// libtorrent itself
@ -300,7 +310,6 @@ POSSIBILITY OF SUCH DAMAGE.
// ==== SOLARIS ===
#elif defined sun || defined __sun
#define TORRENT_SOLARIS
#define TORRENT_COMPLETE_TYPES_REQUIRED 1
#define TORRENT_USE_IFCONF 1
#define TORRENT_HAS_SALEN 0
#define TORRENT_HAS_SEM_RELTIMEDWAIT 1

View File

@ -150,14 +150,14 @@ namespace libtorrent
// copies the structure of the right hand side into this
// entry.
#ifndef TORRENT_NO_DEPRECATE
void operator=(lazy_entry const&);
entry& operator=(lazy_entry const&);
#endif
void operator=(bdecode_node const&);
void operator=(entry const&);
void operator=(dictionary_type const&);
void operator=(string_type const&);
void operator=(list_type const&);
void operator=(integer_type const&);
entry& operator=(bdecode_node const&);
entry& operator=(entry const&);
entry& operator=(dictionary_type const&);
entry& operator=(string_type const&);
entry& operator=(list_type const&);
entry& operator=(integer_type const&);
// The ``integer()``, ``string()``, ``list()`` and ``dict()`` functions
// are accessors that return the respective type. If the ``entry`` object
@ -261,7 +261,7 @@ namespace libtorrent
void to_string_impl(std::string& out, int indent) const;
#if (defined(_MSC_VER) && _MSC_VER < 1310) || TORRENT_COMPLETE_TYPES_REQUIRED
#if TORRENT_COMPLETE_TYPES_REQUIRED
// workaround for msvc-bug.
// assumes sizeof(map<string, char>) == sizeof(map<string, entry>)
// and sizeof(list<char>) == sizeof(list<entry>)

View File

@ -659,8 +659,8 @@ namespace libtorrent
peer_iterator begin() { return m_connections.begin(); }
peer_iterator end() { return m_connections.end(); }
void get_full_peer_list(std::vector<peer_list_entry>& v) const;
void get_peer_info(std::vector<peer_info>& v);
void get_full_peer_list(std::vector<peer_list_entry>* v) const;
void get_peer_info(std::vector<peer_info>* v);
void get_download_queue(std::vector<partial_piece_info>* queue) const;
void refresh_explicit_cache(int cache_size);

View File

@ -52,6 +52,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/file_storage.hpp"
#if TORRENT_COMPLETE_TYPES_REQUIRED
#include "libtorrent/announce_entry.hpp"
#endif
namespace libtorrent
{
class peer_connection;

View File

@ -203,20 +203,17 @@ namespace libtorrent
ipv4_peer(ipv4_peer const& p);
address_v4 addr;
private:
ipv4_peer& operator=(ipv4_peer const&);
};
#if TORRENT_USE_I2P
struct TORRENT_EXTRA_EXPORT i2p_peer : torrent_peer
{
i2p_peer(char const* destination, bool connectable, int src);
i2p_peer(const i2p_peer&);
~i2p_peer();
i2p_peer& operator=(i2p_peer const&);
char* destination;
private:
i2p_peer(const i2p_peer&);
i2p_peer& operator=(i2p_peer const&);
};
#endif
@ -226,10 +223,6 @@ namespace libtorrent
ipv6_peer(tcp::endpoint const& ip, bool connectable, int src);
const address_v6::bytes_type addr;
private:
// explicitly disallow assignment, to silence msvc warning
ipv6_peer& operator=(ipv6_peer const&);
ipv6_peer(ipv6_peer const&);
};
#endif

View File

@ -156,10 +156,11 @@ namespace libtorrent
entry::~entry() { destruct(); }
void entry::operator=(const entry& e)
entry& entry::operator=(const entry& e)
{
destruct();
copy(e);
return *this;
}
entry::integer_type& entry::integer()
@ -321,7 +322,7 @@ namespace libtorrent
}
// convert a bdecode_node into an old skool entry
void entry::operator=(bdecode_node const& e)
entry& entry::operator=(bdecode_node const& e)
{
switch (e.type())
{
@ -355,11 +356,12 @@ namespace libtorrent
destruct();
break;
}
return *this;
}
#ifndef TORRENT_NO_DEPRECATE
// convert a lazy_entry into an old skool entry
void entry::operator=(lazy_entry const& e)
entry& entry::operator=(lazy_entry const& e)
{
switch (e.type())
{
@ -393,10 +395,11 @@ namespace libtorrent
destruct();
break;
}
return *this;
}
#endif
void entry::operator=(dictionary_type const& v)
entry& entry::operator=(dictionary_type const& v)
{
destruct();
new(data) dictionary_type(v);
@ -404,9 +407,10 @@ namespace libtorrent
#ifdef TORRENT_DEBUG
m_type_queried = true;
#endif
return *this;
}
void entry::operator=(string_type const& v)
entry& entry::operator=(string_type const& v)
{
destruct();
new(data) string_type(v);
@ -414,9 +418,10 @@ namespace libtorrent
#ifdef TORRENT_DEBUG
m_type_queried = true;
#endif
return *this;
}
void entry::operator=(list_type const& v)
entry& entry::operator=(list_type const& v)
{
destruct();
new(data) list_type(v);
@ -424,9 +429,10 @@ namespace libtorrent
#ifdef TORRENT_DEBUG
m_type_queried = true;
#endif
return *this;
}
void entry::operator=(integer_type const& v)
entry& entry::operator=(integer_type const& v)
{
destruct();
new(data) integer_type(v);
@ -434,6 +440,7 @@ namespace libtorrent
#ifdef TORRENT_DEBUG
m_type_queried = true;
#endif
return *this;
}
bool entry::operator==(entry const& e) const

View File

@ -7079,12 +7079,12 @@ namespace libtorrent
}
}
void torrent::get_full_peer_list(std::vector<peer_list_entry>& v) const
void torrent::get_full_peer_list(std::vector<peer_list_entry>* v) const
{
v.clear();
v->clear();
if (!m_peer_list) return;
v.reserve(m_peer_list->num_peers());
v->reserve(m_peer_list->num_peers());
for (peer_list::const_iterator i = m_peer_list->begin_peer();
i != m_peer_list->end_peer(); ++i)
{
@ -7093,13 +7093,13 @@ namespace libtorrent
e.flags = (*i)->banned ? peer_list_entry::banned : 0;
e.failcount = (*i)->failcount;
e.source = (*i)->source;
v.push_back(e);
v->push_back(e);
}
}
void torrent::get_peer_info(std::vector<peer_info>& v)
void torrent::get_peer_info(std::vector<peer_info>* v)
{
v.clear();
v->clear();
for (peer_iterator i = begin();
i != end(); ++i)
{
@ -7110,8 +7110,8 @@ namespace libtorrent
// not be included in this list
if (peer->associated_torrent().expired()) continue;
v.push_back(peer_info());
peer_info& p = v.back();
v->push_back(peer_info());
peer_info& p = v->back();
peer->get_peer_info(p);
#ifndef TORRENT_NO_DEPRECATE

View File

@ -59,6 +59,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/thread.hpp"
#include "libtorrent/announce_entry.hpp"
#if TORRENT_COMPLETE_TYPES_REQUIRED
#include "libtorrent/peer_info.hpp" // for peer_list_entry
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-macros"
@ -818,12 +822,12 @@ namespace libtorrent
void torrent_handle::get_full_peer_list(std::vector<peer_list_entry>& v) const
{
TORRENT_SYNC_CALL1(get_full_peer_list, boost::ref(v));
TORRENT_SYNC_CALL1(get_full_peer_list, &v);
}
void torrent_handle::get_peer_info(std::vector<peer_info>& v) const
{
TORRENT_SYNC_CALL1(get_peer_info, boost::ref(v));
TORRENT_SYNC_CALL1(get_peer_info, &v);
}
void torrent_handle::get_download_queue(std::vector<partial_piece_info>& queue) const

View File

@ -259,6 +259,19 @@ namespace libtorrent
i2p_peer::~i2p_peer()
{ free(destination); }
i2p_peer::i2p_peer(const i2p_peer& rhs)
: torrent_peer(rhs.port, rhs.connectable, rhs.source)
, destination(allocate_string_copy(rhs.destination))
{}
i2p_peer& i2p_peer::operator=(i2p_peer const& rhs)
{
char* tmp = allocate_string_copy(rhs.destination);
free(destination);
destination = tmp;
return *this;
}
#endif // TORRENT_USE_I2P
#if TORRENT_USE_IPV6