silence some warnings on msvc

This commit is contained in:
Arvid Norberg 2015-04-27 02:21:12 +00:00
parent f97168241f
commit 2fff222235
26 changed files with 126 additions and 31 deletions

10
Jamfile
View File

@ -266,7 +266,15 @@ rule warnings ( properties * )
{ {
# disable warning C4503: decorated name length exceeded, name was truncated # disable warning C4503: decorated name length exceeded, name was truncated
result += <cflags>/wd4503 ; result += <cflags>/wd4503 ;
result += <cflags>/W4 ; result += <warnings>all ;
# enable these warnings again, once the other ones are dealt with
# disable warning C4389: signed/unsigned mismatch
result += <cflags>/wd4389 ;
result += <cflags>/wd4245 ;
# disable warning C4244: 'argument' : conversion from 'int' to 'unsigned short', possible loss of data
result += <cflags>/wd4244 ;
} }
return $(result) ; return $(result) ;

View File

@ -264,6 +264,9 @@ namespace libtorrent {
#endif #endif
private: private:
// explicitly disallow assignment, to silence msvc warning
alert& operator=(alert const&);
time_point m_timestamp; time_point m_timestamp;
}; };

View File

@ -45,6 +45,18 @@ std::string demangle(char const* name);
TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth = 0); TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth = 0);
#endif #endif
// this is to disable the warning of conditional expressions
// being constant in msvc
#ifdef _MSC_VER
#define TORRENT_WHILE_0 \
__pragma( warning(push) ) \
__pragma( warning(disable:4127) ) \
while (0) \
__pragma( warning(pop) )
#else
#define TORRENT_WHILE_0 while (0)
#endif
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS
#ifdef TORRENT_PRODUCTION_ASSERTS #ifdef TORRENT_PRODUCTION_ASSERTS
@ -70,15 +82,15 @@ TORRENT_EXPORT void assert_fail(const char* expr, int line
, char const* file, char const* function, char const* val, int kind = 0); , char const* file, char const* function, char const* val, int kind = 0);
#define TORRENT_ASSERT_PRECOND(x) \ #define TORRENT_ASSERT_PRECOND(x) \
do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, 0, 1); } while (false) do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, 0, 1); } TORRENT_WHILE_0
#define TORRENT_ASSERT(x) \ #define TORRENT_ASSERT(x) \
do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, 0, 0); } while (false) do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, 0, 0); } TORRENT_WHILE_0
#if TORRENT_USE_IOSTREAM #if TORRENT_USE_IOSTREAM
#define TORRENT_ASSERT_VAL(x, y) \ #define TORRENT_ASSERT_VAL(x, y) \
do { if (x) {} else { std::stringstream __s__; __s__ << #y ": " << y; \ do { if (x) {} else { std::stringstream __s__; __s__ << #y ": " << y; \
assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, __s__.str().c_str(), 0); } } while (false) assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, __s__.str().c_str(), 0); } } TORRENT_WHILE_0
#else #else
#define TORRENT_ASSERT_VAL(x, y) TORRENT_ASSERT(x) #define TORRENT_ASSERT_VAL(x, y) TORRENT_ASSERT(x)
#endif #endif
@ -92,9 +104,9 @@ TORRENT_EXPORT void assert_fail(const char* expr, int line
#else // TORRENT_USE_ASSERTS #else // TORRENT_USE_ASSERTS
#define TORRENT_ASSERT_PRECOND(a) do {} while(false) #define TORRENT_ASSERT_PRECOND(a) do {} TORRENT_WHILE_0
#define TORRENT_ASSERT(a) do {} while(false) #define TORRENT_ASSERT(a) do {} TORRENT_WHILE_0
#define TORRENT_ASSERT_VAL(a, b) do {} while(false) #define TORRENT_ASSERT_VAL(a, b) do {} TORRENT_WHILE_0
#endif // TORRENT_USE_ASSERTS #endif // TORRENT_USE_ASSERTS

View File

@ -1228,6 +1228,9 @@ namespace libtorrent
#endif #endif
; ;
session_interface& m_ses; session_interface& m_ses;
private:
// explicitly disallow assignment, to silence msvc warning
tracker_logger& operator=(tracker_logger const&);
}; };
#endif #endif

View File

@ -623,7 +623,16 @@ int snprintf(char* buf, int len, char const* fmt, ...)
#endif #endif
#if defined _MSC_VER && _MSC_VER <= 1200 #if defined _MSC_VER && _MSC_VER <= 1200
#define for if (false) {} else for // this is here to provide a standard-conforming for
// keyword for old versions of msvc. The pragmas are
// there to silence the warning it produces by using
// a constant as conditional
#define for \
__pragma( warning(push) ) \
__pragma( warning(disable:4127) ) \
if (false) {} else \
__pragma( warning(pop) )
for
#endif #endif
#if TORRENT_BROKEN_UNIONS #if TORRENT_BROKEN_UNIONS

View File

@ -111,6 +111,9 @@ namespace libtorrent
{ return m_buf == 0? 0: &disk_buffer_holder::release; } { return m_buf == 0? 0: &disk_buffer_holder::release; }
private: private:
// explicitly disallow assignment, to silence msvc warning
disk_buffer_holder& operator=(disk_buffer_holder const&);
buffer_allocator_interface& m_allocator; buffer_allocator_interface& m_allocator;
char* m_buf; char* m_buf;
block_cache_reference m_ref; block_cache_reference m_ref;

View File

@ -129,6 +129,8 @@ public:
void send_name_lookup(boost::shared_ptr<handler_type> h); void send_name_lookup(boost::shared_ptr<handler_type> h);
private: private:
// explicitly disallow assignment, to silence msvc warning
i2p_stream& operator=(i2p_stream const&);
void do_connect(error_code const& e, tcp::resolver::iterator i void do_connect(error_code const& e, tcp::resolver::iterator i
, boost::shared_ptr<handler_type> h); , boost::shared_ptr<handler_type> h);
@ -185,6 +187,8 @@ public:
void async_name_lookup(char const* name, name_lookup_handler handler); void async_name_lookup(char const* name, name_lookup_handler handler);
private: private:
// explicitly disallow assignment, to silence msvc warning
i2p_connection& operator=(i2p_connection const&);
void on_sam_connect(error_code const& ec, i2p_stream::handler_type const& h void on_sam_connect(error_code const& ec, i2p_stream::handler_type const& h
, boost::shared_ptr<i2p_stream>); , boost::shared_ptr<i2p_stream>);

View File

@ -78,10 +78,9 @@ namespace libtorrent
#define INVARIANT_CHECK \ #define INVARIANT_CHECK \
invariant_checker const& _invariant_check = make_invariant_checker(*this); \ invariant_checker const& _invariant_check = make_invariant_checker(*this); \
(void)_invariant_check; \ (void)_invariant_check
do {} while (false)
#else #else
#define INVARIANT_CHECK do {} while (false) #define INVARIANT_CHECK do {} TORRENT_WHILE_0
#endif #endif
#endif // TORRENT_INVARIANT_ACCESS_HPP_INCLUDED #endif // TORRENT_INVARIANT_ACCESS_HPP_INCLUDED

View File

@ -58,6 +58,9 @@ struct msg
// the address of the process sending or receiving // the address of the process sending or receiving
// the message. // the message.
udp::endpoint addr; udp::endpoint addr;
private:
// explicitly disallow assignment, to silence msvc warning
msg& operator=(msg const&);
}; };
} } } }

View File

@ -147,6 +147,9 @@ namespace libtorrent
piece_block const& block; piece_block const& block;
bool operator()(pending_block const& pb) const bool operator()(pending_block const& pb) const
{ return pb.block == block; } { return pb.block == block; }
private:
// explicitly disallow assignment, to silence msvc warning
has_block& operator=(has_block const&);
}; };
// argument pack passed to peer_connection constructor // argument pack passed to peer_connection constructor
@ -257,6 +260,9 @@ namespace libtorrent
// when this is set, the transfer stats for this connection // when this is set, the transfer stats for this connection
// is not included in the torrent or session stats // is not included in the torrent or session stats
bool m_ignore_stats:1; bool m_ignore_stats:1;
private:
// explicitly disallow assignment, to silence msvc warning
peer_connection_hot_members& operator=(peer_connection_hot_members const&);
}; };
class TORRENT_EXTRA_EXPORT peer_connection class TORRENT_EXTRA_EXPORT peer_connection
@ -805,6 +811,8 @@ namespace libtorrent
virtual int timeout() const; virtual int timeout() const;
private: private:
// explicitly disallow assignment, to silence msvc warning
peer_connection& operator=(peer_connection const&);
void do_update_interest(); void do_update_interest();
int preferred_caching() const; int preferred_caching() const;

View File

@ -138,6 +138,9 @@ struct receive_buffer
#endif #endif
private: private:
// explicitly disallow assignment, to silence msvc warning
receive_buffer& operator=(receive_buffer const&);
// recv_buf.begin (start of actual receive buffer) // recv_buf.begin (start of actual receive buffer)
// | // |
// | m_recv_start (logical start of current // | m_recv_start (logical start of current
@ -263,6 +266,9 @@ struct crypto_receive_buffer
, std::size_t bytes_transfered); , std::size_t bytes_transfered);
private: private:
// explicitly disallow assignment, to silence msvc warning
crypto_receive_buffer& operator=(crypto_receive_buffer const&);
int m_recv_pos; int m_recv_pos;
int m_packet_size; int m_packet_size;
int m_soft_packet_size; int m_soft_packet_size;

View File

@ -233,7 +233,11 @@ namespace libtorrent
void load_state(bdecode_node const& rd); void load_state(bdecode_node const& rd);
void save_state(entry& rd) const; void save_state(entry& rd) const;
// private: private:
friend struct aux::session_impl;
// explicitly disallow assignment, to silence msvc warning
feed& operator=(feed const&);
void add_item(feed_item const& item); void add_item(feed_item const& item);
@ -257,9 +261,9 @@ namespace libtorrent
std::map<std::string, time_t> m_added; std::map<std::string, time_t> m_added;
std::string m_title; std::string m_title;
std::string m_description; std::string m_description;
time_t m_last_attempt; time_t m_last_attempt;
time_t m_last_update; time_t m_last_update;
// refresh rate of this feed in minutes // refresh rate of this feed in minutes
int m_ttl; int m_ttl;
// the number of update failures in a row // the number of update failures in a row

View File

@ -289,6 +289,8 @@ namespace libtorrent
} }
private: private:
// explicitly disallow assignment, to silence msvc warning
socket_type& operator=(socket_type const&);
void destruct(); void destruct();
void construct(int type, void* userdata); void construct(int type, void* userdata);
@ -316,6 +318,8 @@ namespace libtorrent
>::value >::value
}; };
// TODO: 2 it would be nice to use aligned_storage here when
// building on c++11
boost::int64_t m_data[(storage_size + sizeof(boost::int64_t) - 1) boost::int64_t m_data[(storage_size + sizeof(boost::int64_t) - 1)
/ sizeof(boost::int64_t)]; / sizeof(boost::int64_t)];
}; };

View File

@ -198,6 +198,8 @@ namespace libtorrent
ipv4_peer(tcp::endpoint const& ip, bool connectable, int src); ipv4_peer(tcp::endpoint const& ip, bool connectable, int src);
address_v4 addr; address_v4 addr;
private:
ipv4_peer& operator=(ipv4_peer const&);
}; };
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
@ -207,6 +209,8 @@ namespace libtorrent
~i2p_peer(); ~i2p_peer();
char* destination; char* destination;
private:
i2p_peer& operator=(i2p_peer const&);
}; };
#endif #endif
@ -216,6 +220,9 @@ namespace libtorrent
ipv6_peer(tcp::endpoint const& ip, bool connectable, int src); ipv6_peer(tcp::endpoint const& ip, bool connectable, int src);
const address_v6::bytes_type addr; const address_v6::bytes_type addr;
private:
// explicitly disallow assignment, to silence msvc warning
ipv6_peer& operator=(ipv6_peer const&);
}; };
#endif #endif

View File

@ -101,6 +101,9 @@ namespace libtorrent
void inc_stats_counter(int counter, int delta = 1); void inc_stats_counter(int counter, int delta = 1);
private: private:
// explicitly disallow assignment, to silence msvc warning
utp_socket_manager& operator=(utp_socket_manager const&);
udp_socket& m_sock; udp_socket& m_sock;
incoming_utp_callback_t m_cb; incoming_utp_callback_t m_cb;

View File

@ -465,6 +465,8 @@ public:
} }
private: private:
// explicitly disallow assignment, to silence msvc warning
utp_stream& operator=(utp_stream const&);
void cancel_handlers(error_code const&); void cancel_handlers(error_code const&);

View File

@ -692,7 +692,7 @@ namespace libtorrent
ec = make_error_code(code); \ ec = make_error_code(code); \
if (error_pos) *error_pos = start - orig_start; \ if (error_pos) *error_pos = start - orig_start; \
goto done; \ goto done; \
} while (false) } TORRENT_WHILE_0
int bdecode(char const* start, char const* end, bdecode_node& ret int bdecode(char const* start, char const* end, bdecode_node& ret
, error_code& ec, int* error_pos, int depth_limit, int token_limit) , error_code& ec, int* error_pos, int depth_limit, int token_limit)

View File

@ -280,10 +280,10 @@ const char* const job_action_name[] =
#define TORRENT_PIECE_ASSERT(cond, piece) \ #define TORRENT_PIECE_ASSERT(cond, piece) \
do { if (!(cond)) { assert_print_piece(piece); assert_fail(#cond, __LINE__, __FILE__, TORRENT_FUNCTION, 0); } } while(false) do { if (!(cond)) { assert_print_piece(piece); assert_fail(#cond, __LINE__, __FILE__, TORRENT_FUNCTION, 0); } } TORRENT_WHILE_0
#else #else
#define TORRENT_PIECE_ASSERT(cond, piece) do {} while(false) #define TORRENT_PIECE_ASSERT(cond, piece) do {} TORRENT_WHILE_0
#endif #endif
cached_piece_entry::cached_piece_entry() cached_piece_entry::cached_piece_entry()

View File

@ -60,7 +60,11 @@ POSSIBILITY OF SUCH DAMAGE.
#define DEBUG_DISK_THREAD 0 #define DEBUG_DISK_THREAD 0
#define DLOG if (DEBUG_DISK_THREAD) debug_log #if DEBUG_DISK_THREAD
#define DLOG debug_log
#else
#define DLOG TORRENT_WHILE_0 debug_log
#endif
namespace libtorrent namespace libtorrent
{ {
@ -73,10 +77,10 @@ namespace libtorrent
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS
#define TORRENT_PIECE_ASSERT(cond, piece) \ #define TORRENT_PIECE_ASSERT(cond, piece) \
do { if (!(cond)) { assert_print_piece(piece); assert_fail(#cond, __LINE__, __FILE__, TORRENT_FUNCTION, 0); } } while(false) do { if (!(cond)) { assert_print_piece(piece); assert_fail(#cond, __LINE__, __FILE__, TORRENT_FUNCTION, 0); } } TORRENT_WHILE_0
#else #else
#define TORRENT_PIECE_ASSERT(cond, piece) do {} while(false) #define TORRENT_PIECE_ASSERT(cond, piece) do {} TORRENT_WHILE_0
#endif #endif
namespace { namespace {

View File

@ -50,10 +50,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/entry.hpp" #include "libtorrent/entry.hpp"
#include "libtorrent/hex.hpp" #include "libtorrent/hex.hpp"
#if defined(_MSC_VER)
#define for if (false) {} else for
#endif
namespace namespace
{ {
template <class T> template <class T>

View File

@ -785,6 +785,10 @@ struct immutable_item_comparator
return lhs.second.num_announcers / 5 - l_distance < rhs.second.num_announcers / 5 - r_distance; return lhs.second.num_announcers / 5 - l_distance < rhs.second.num_announcers / 5 - r_distance;
} }
private:
// explicitly disallow assignment, to silence msvc warning
immutable_item_comparator& operator=(immutable_item_comparator const&);
node_id const& m_our_id; node_id const& m_our_id;
}; };

View File

@ -68,7 +68,7 @@ namespace libtorrent
return -1; return -1;
} }
#define TORRENT_FAIL_BDECODE(code) do { ec = make_error_code(code); return fail(error_pos, stack, start, orig_start); } while (false) #define TORRENT_FAIL_BDECODE(code) do { ec = make_error_code(code); return fail(error_pos, stack, start, orig_start); } TORRENT_WHILE_0
bool numeric(char c) { return c >= '0' && c <= '9'; } bool numeric(char c) { return c >= '0' && c <= '9'; }

View File

@ -90,8 +90,17 @@ POSSIBILITY OF SUCH DAMAGE.
#define DEBUG_STORAGE 0 #define DEBUG_STORAGE 0
#define DEBUG_DELETE_FILES 0 #define DEBUG_DELETE_FILES 0
#define DLOG if (DEBUG_STORAGE) fprintf #if DEBUG_STORAGE
#define DFLOG if (DEBUG_DELETE_FILES) fprintf #define DLOG fprintf
#else
#define DLOG TORRENT_WHILE_0 fprintf
#endif
#if DEBUG_DELETE_FILES
#define DFLOG fprintf
#else
#define DFLOG TORRENT_WHILE_0 fprintf
#endif
namespace libtorrent namespace libtorrent
{ {

View File

@ -123,7 +123,7 @@ udp_socket::~udp_socket()
int& m; int& m;
}; };
#else #else
#define CHECK_MAGIC do {} while (false) #define CHECK_MAGIC do {} TORRENT_WHILE_0
#endif #endif
void udp_socket::send_hostname(char const* hostname, int port void udp_socket::send_hostname(char const* hostname, int port

View File

@ -47,6 +47,10 @@ namespace libtorrent
wchar_t const* dst_start = wide.c_str(); wchar_t const* dst_start = wide.c_str();
char const* src_start = utf8.c_str(); char const* src_start = utf8.c_str();
ConversionResult ret; ConversionResult ret;
// TODO: 3 refactor this to use wchar_t as a template
// it would cause less code to be generated without
// relying on dead-code elimination and fix msvc constant
// expression warning
if (sizeof(wchar_t) == sizeof(UTF32)) if (sizeof(wchar_t) == sizeof(UTF32))
{ {
ret = ConvertUTF8toUTF32((const UTF8**)&src_start, (const UTF8*)src_start ret = ConvertUTF8toUTF32((const UTF8**)&src_start, (const UTF8*)src_start

View File

@ -89,13 +89,13 @@ void utp_log(char const* fmt, ...)
#if TORRENT_VERBOSE_UTP_LOG #if TORRENT_VERBOSE_UTP_LOG
#define UTP_LOGV utp_log #define UTP_LOGV utp_log
#else #else
#define UTP_LOGV if (false) printf #define UTP_LOGV TORRENT_WHILE_0 printf
#endif #endif
#else #else
#define UTP_LOG if (false) printf #define UTP_LOG TORRENT_WHILE_0 printf
#define UTP_LOGV if (false) printf #define UTP_LOGV TORRENT_WHILE_0 printf
#endif #endif