diff --git a/Jamfile b/Jamfile index b98dc5299..84fc70075 100755 --- a/Jamfile +++ b/Jamfile @@ -266,7 +266,15 @@ rule warnings ( properties * ) { # disable warning C4503: decorated name length exceeded, name was truncated result += /wd4503 ; - result += /W4 ; + result += all ; + +# enable these warnings again, once the other ones are dealt with + +# disable warning C4389: signed/unsigned mismatch + result += /wd4389 ; + result += /wd4245 ; +# disable warning C4244: 'argument' : conversion from 'int' to 'unsigned short', possible loss of data + result += /wd4244 ; } return $(result) ; diff --git a/include/libtorrent/alert.hpp b/include/libtorrent/alert.hpp index f4fd26dae..cf166e65c 100644 --- a/include/libtorrent/alert.hpp +++ b/include/libtorrent/alert.hpp @@ -264,6 +264,9 @@ namespace libtorrent { #endif private: + // explicitly disallow assignment, to silence msvc warning + alert& operator=(alert const&); + time_point m_timestamp; }; diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index 1bd449764..0ed5983ac 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -45,6 +45,18 @@ std::string demangle(char const* name); TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth = 0); #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 #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); #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) \ - 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 #define TORRENT_ASSERT_VAL(x, 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 #define TORRENT_ASSERT_VAL(x, y) TORRENT_ASSERT(x) #endif @@ -92,9 +104,9 @@ TORRENT_EXPORT void assert_fail(const char* expr, int line #else // TORRENT_USE_ASSERTS -#define TORRENT_ASSERT_PRECOND(a) do {} while(false) -#define TORRENT_ASSERT(a) do {} while(false) -#define TORRENT_ASSERT_VAL(a, b) do {} while(false) +#define TORRENT_ASSERT_PRECOND(a) do {} TORRENT_WHILE_0 +#define TORRENT_ASSERT(a) do {} TORRENT_WHILE_0 +#define TORRENT_ASSERT_VAL(a, b) do {} TORRENT_WHILE_0 #endif // TORRENT_USE_ASSERTS diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 193d494de..32a3820bc 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -1228,6 +1228,9 @@ namespace libtorrent #endif ; session_interface& m_ses; + private: + // explicitly disallow assignment, to silence msvc warning + tracker_logger& operator=(tracker_logger const&); }; #endif diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index f1c545de4..d0dcc5296 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -623,7 +623,16 @@ int snprintf(char* buf, int len, char const* fmt, ...) #endif #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 #if TORRENT_BROKEN_UNIONS diff --git a/include/libtorrent/disk_buffer_holder.hpp b/include/libtorrent/disk_buffer_holder.hpp index b7d23937a..93f313df1 100644 --- a/include/libtorrent/disk_buffer_holder.hpp +++ b/include/libtorrent/disk_buffer_holder.hpp @@ -111,6 +111,9 @@ namespace libtorrent { return m_buf == 0? 0: &disk_buffer_holder::release; } private: + // explicitly disallow assignment, to silence msvc warning + disk_buffer_holder& operator=(disk_buffer_holder const&); + buffer_allocator_interface& m_allocator; char* m_buf; block_cache_reference m_ref; diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index 445d4518f..afbc14707 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -129,6 +129,8 @@ public: void send_name_lookup(boost::shared_ptr h); 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 , boost::shared_ptr h); @@ -185,6 +187,8 @@ public: void async_name_lookup(char const* name, name_lookup_handler handler); 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 , boost::shared_ptr); diff --git a/include/libtorrent/invariant_check.hpp b/include/libtorrent/invariant_check.hpp index 8e9e7c0ef..60c260b6a 100644 --- a/include/libtorrent/invariant_check.hpp +++ b/include/libtorrent/invariant_check.hpp @@ -78,10 +78,9 @@ namespace libtorrent #define INVARIANT_CHECK \ invariant_checker const& _invariant_check = make_invariant_checker(*this); \ - (void)_invariant_check; \ - do {} while (false) + (void)_invariant_check #else -#define INVARIANT_CHECK do {} while (false) +#define INVARIANT_CHECK do {} TORRENT_WHILE_0 #endif #endif // TORRENT_INVARIANT_ACCESS_HPP_INCLUDED diff --git a/include/libtorrent/kademlia/msg.hpp b/include/libtorrent/kademlia/msg.hpp index 9c0d67fc5..57db50bbb 100644 --- a/include/libtorrent/kademlia/msg.hpp +++ b/include/libtorrent/kademlia/msg.hpp @@ -58,6 +58,9 @@ struct msg // the address of the process sending or receiving // the message. udp::endpoint addr; +private: + // explicitly disallow assignment, to silence msvc warning + msg& operator=(msg const&); }; } } diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 138c6d18f..bebfb5e5a 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -147,6 +147,9 @@ namespace libtorrent piece_block const& block; bool operator()(pending_block const& pb) const { 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 @@ -257,6 +260,9 @@ namespace libtorrent // when this is set, the transfer stats for this connection // is not included in the torrent or session stats 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 @@ -805,6 +811,8 @@ namespace libtorrent virtual int timeout() const; private: + // explicitly disallow assignment, to silence msvc warning + peer_connection& operator=(peer_connection const&); void do_update_interest(); int preferred_caching() const; diff --git a/include/libtorrent/receive_buffer.hpp b/include/libtorrent/receive_buffer.hpp index a909c75c2..6ea0cb70a 100644 --- a/include/libtorrent/receive_buffer.hpp +++ b/include/libtorrent/receive_buffer.hpp @@ -138,6 +138,9 @@ struct receive_buffer #endif private: + // explicitly disallow assignment, to silence msvc warning + receive_buffer& operator=(receive_buffer const&); + // recv_buf.begin (start of actual receive buffer) // | // | m_recv_start (logical start of current @@ -263,6 +266,9 @@ struct crypto_receive_buffer , std::size_t bytes_transfered); private: + // explicitly disallow assignment, to silence msvc warning + crypto_receive_buffer& operator=(crypto_receive_buffer const&); + int m_recv_pos; int m_packet_size; int m_soft_packet_size; diff --git a/include/libtorrent/rss.hpp b/include/libtorrent/rss.hpp index ab2e89829..53b313aa0 100644 --- a/include/libtorrent/rss.hpp +++ b/include/libtorrent/rss.hpp @@ -233,8 +233,12 @@ namespace libtorrent void load_state(bdecode_node const& rd); 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); feed_handle my_handle(); @@ -257,9 +261,9 @@ namespace libtorrent std::map m_added; std::string m_title; - std::string m_description; + std::string m_description; time_t m_last_attempt; - time_t m_last_update; + time_t m_last_update; // refresh rate of this feed in minutes int m_ttl; // the number of update failures in a row diff --git a/include/libtorrent/socket_type.hpp b/include/libtorrent/socket_type.hpp index 24b826529..8326fed88 100644 --- a/include/libtorrent/socket_type.hpp +++ b/include/libtorrent/socket_type.hpp @@ -289,6 +289,8 @@ namespace libtorrent } private: + // explicitly disallow assignment, to silence msvc warning + socket_type& operator=(socket_type const&); void destruct(); void construct(int type, void* userdata); @@ -316,6 +318,8 @@ namespace libtorrent >::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) / sizeof(boost::int64_t)]; }; diff --git a/include/libtorrent/torrent_peer.hpp b/include/libtorrent/torrent_peer.hpp index 58c83766f..826166703 100644 --- a/include/libtorrent/torrent_peer.hpp +++ b/include/libtorrent/torrent_peer.hpp @@ -198,6 +198,8 @@ namespace libtorrent ipv4_peer(tcp::endpoint const& ip, bool connectable, int src); address_v4 addr; + private: + ipv4_peer& operator=(ipv4_peer const&); }; #if TORRENT_USE_I2P @@ -207,6 +209,8 @@ namespace libtorrent ~i2p_peer(); char* destination; + private: + i2p_peer& operator=(i2p_peer const&); }; #endif @@ -216,6 +220,9 @@ 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&); }; #endif diff --git a/include/libtorrent/utp_socket_manager.hpp b/include/libtorrent/utp_socket_manager.hpp index d9c83f181..cb47a78b9 100644 --- a/include/libtorrent/utp_socket_manager.hpp +++ b/include/libtorrent/utp_socket_manager.hpp @@ -101,6 +101,9 @@ namespace libtorrent void inc_stats_counter(int counter, int delta = 1); private: + // explicitly disallow assignment, to silence msvc warning + utp_socket_manager& operator=(utp_socket_manager const&); + udp_socket& m_sock; incoming_utp_callback_t m_cb; diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index 85c27baf2..8d188e6bd 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -465,6 +465,8 @@ public: } private: + // explicitly disallow assignment, to silence msvc warning + utp_stream& operator=(utp_stream const&); void cancel_handlers(error_code const&); diff --git a/src/bdecode.cpp b/src/bdecode.cpp index 6e45eefac..f0b8046ab 100644 --- a/src/bdecode.cpp +++ b/src/bdecode.cpp @@ -692,7 +692,7 @@ namespace libtorrent ec = make_error_code(code); \ if (error_pos) *error_pos = start - orig_start; \ goto done; \ - } while (false) + } TORRENT_WHILE_0 int bdecode(char const* start, char const* end, bdecode_node& ret , error_code& ec, int* error_pos, int depth_limit, int token_limit) diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 9a485b0fb..5532f367c 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -280,10 +280,10 @@ const char* const job_action_name[] = #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 -#define TORRENT_PIECE_ASSERT(cond, piece) do {} while(false) +#define TORRENT_PIECE_ASSERT(cond, piece) do {} TORRENT_WHILE_0 #endif cached_piece_entry::cached_piece_entry() diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index e37d827f8..ce5189cfc 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -60,7 +60,11 @@ POSSIBILITY OF SUCH DAMAGE. #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 { @@ -73,10 +77,10 @@ namespace libtorrent #if TORRENT_USE_ASSERTS #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 -#define TORRENT_PIECE_ASSERT(cond, piece) do {} while(false) +#define TORRENT_PIECE_ASSERT(cond, piece) do {} TORRENT_WHILE_0 #endif namespace { diff --git a/src/entry.cpp b/src/entry.cpp index 816ac0a57..777cb8fd9 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -50,10 +50,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/entry.hpp" #include "libtorrent/hex.hpp" -#if defined(_MSC_VER) -#define for if (false) {} else for -#endif - namespace { template diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index e845ef047..24801ce49 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -785,6 +785,10 @@ struct immutable_item_comparator 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; }; diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index 6da0ea744..785c6d6aa 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -68,7 +68,7 @@ namespace libtorrent 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'; } diff --git a/src/storage.cpp b/src/storage.cpp index 998e53b7f..618a2be93 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -90,8 +90,17 @@ POSSIBILITY OF SUCH DAMAGE. #define DEBUG_STORAGE 0 #define DEBUG_DELETE_FILES 0 -#define DLOG if (DEBUG_STORAGE) fprintf -#define DFLOG if (DEBUG_DELETE_FILES) fprintf +#if DEBUG_STORAGE +#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 { diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 38841061c..f39aa0166 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -123,7 +123,7 @@ udp_socket::~udp_socket() int& m; }; #else - #define CHECK_MAGIC do {} while (false) + #define CHECK_MAGIC do {} TORRENT_WHILE_0 #endif void udp_socket::send_hostname(char const* hostname, int port diff --git a/src/utf8.cpp b/src/utf8.cpp index 92ef3bc6e..00d557110 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -47,6 +47,10 @@ namespace libtorrent wchar_t const* dst_start = wide.c_str(); char const* src_start = utf8.c_str(); 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)) { ret = ConvertUTF8toUTF32((const UTF8**)&src_start, (const UTF8*)src_start diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index dd251939a..35c0c5fce 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -89,13 +89,13 @@ void utp_log(char const* fmt, ...) #if TORRENT_VERBOSE_UTP_LOG #define UTP_LOGV utp_log #else -#define UTP_LOGV if (false) printf +#define UTP_LOGV TORRENT_WHILE_0 printf #endif #else -#define UTP_LOG if (false) printf -#define UTP_LOGV if (false) printf +#define UTP_LOG TORRENT_WHILE_0 printf +#define UTP_LOGV TORRENT_WHILE_0 printf #endif