From 533699bbb5cf8d819ad44399532a5c4df8915078 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 25 Jan 2017 18:04:22 -0500 Subject: [PATCH] making strong_typedef::UnderlyingType constexpr and warnigs cleanup --- Jamfile | 3 +++ include/libtorrent/peer_class_type_filter.hpp | 17 ++++------------- include/libtorrent/piece_block_progress.hpp | 8 +------- include/libtorrent/piece_picker.hpp | 9 --------- include/libtorrent/session_handle.hpp | 9 --------- include/libtorrent/torrent_status.hpp | 9 --------- include/libtorrent/units.hpp | 2 +- 7 files changed, 9 insertions(+), 48 deletions(-) diff --git a/Jamfile b/Jamfile index 5837da7f2..c5308ce57 100644 --- a/Jamfile +++ b/Jamfile @@ -276,6 +276,9 @@ rule warnings ( properties * ) result += /wd4275 ; # disable warning C4373: virtual function overrides, previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers result += /wd4373 ; + # C4268: 'identifier' : 'const' static/global data initialized + # with compiler generated default constructor fills the object with zeros + result += /wd4268 ; } return $(result) ; diff --git a/include/libtorrent/peer_class_type_filter.hpp b/include/libtorrent/peer_class_type_filter.hpp index 61f6f0a3a..a9758bf9c 100644 --- a/include/libtorrent/peer_class_type_filter.hpp +++ b/include/libtorrent/peer_class_type_filter.hpp @@ -67,10 +67,8 @@ namespace libtorrent // to new peers based on socket type. void add(socket_type_t st, peer_class_t const peer_class) { - TORRENT_ASSERT(peer_class >= peer_class_t{0}); TORRENT_ASSERT(peer_class < peer_class_t{32}); - if (peer_class < peer_class_t{0} - || peer_class > peer_class_t{31}) return; + if (peer_class > peer_class_t{31}) return; TORRENT_ASSERT(st < num_socket_types && st >= 0); if (st < 0 || st >= num_socket_types) return; @@ -78,10 +76,8 @@ namespace libtorrent } void remove(socket_type_t st, peer_class_t const peer_class) { - TORRENT_ASSERT(peer_class >= peer_class_t{0}); TORRENT_ASSERT(peer_class < peer_class_t{32}); - if (peer_class < peer_class_t{0} - || peer_class > peer_class_t{31}) return; + if (peer_class > peer_class_t{31}) return; TORRENT_ASSERT(st < num_socket_types && st >= 0); if (st < 0 || st >= num_socket_types) return; @@ -95,10 +91,8 @@ namespace libtorrent // peer classes in the ``peer_class_type_filter`` are 32 bits. void disallow(socket_type_t st, peer_class_t const peer_class) { - TORRENT_ASSERT(peer_class >= peer_class_t{0}); TORRENT_ASSERT(peer_class < peer_class_t{32}); - if (peer_class < peer_class_t{0} - || peer_class > peer_class_t{31}) return; + if (peer_class > peer_class_t{31}) return; TORRENT_ASSERT(st < num_socket_types && st >= 0); if (st < 0 || st >= num_socket_types) return; @@ -106,10 +100,8 @@ namespace libtorrent } void allow(socket_type_t st, peer_class_t const peer_class) { - TORRENT_ASSERT(peer_class >= peer_class_t{0}); TORRENT_ASSERT(peer_class < peer_class_t{32}); - if (peer_class < peer_class_t{0} - || peer_class > peer_class_t{31}) return; + if (peer_class > peer_class_t{31}) return; TORRENT_ASSERT(st < num_socket_types && st >= 0); if (st < 0 || st >= num_socket_types) return; @@ -142,4 +134,3 @@ namespace libtorrent } #endif - diff --git a/include/libtorrent/piece_block_progress.hpp b/include/libtorrent/piece_block_progress.hpp index a845588f4..3e26af739 100644 --- a/include/libtorrent/piece_block_progress.hpp +++ b/include/libtorrent/piece_block_progress.hpp @@ -34,19 +34,13 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_PIECE_BLOCK_PROGRESS_HPP_INCLUDED #include "libtorrent/config.hpp" +#include "libtorrent/units.hpp" namespace libtorrent { struct piece_block_progress { -#ifdef _MSC_VER -#pragma warning(push, 1) -#pragma warning(disable : 4268) -#endif constexpr static piece_index_t invalid_index{-1}; -#ifdef _MSC_VER -#pragma warning(pop) -#endif // the piece and block index // determines exactly which diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 080788f7c..f04052f28 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -572,20 +572,11 @@ namespace libtorrent std::set have_peers; #endif -#ifdef _MSC_VER -#pragma warning(push, 1) -#pragma warning(disable : 4268) -#endif - // index is set to this to indicate that we have the // piece. There is no entry for the piece in the // buckets if this is the case. constexpr static prio_index_t we_have_index{-1}; -#ifdef _MSC_VER -#pragma warning(pop) -#endif - enum : std::uint32_t { // the priority value that means the piece is filtered diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index 7bfdce1a5..ce0f7ff56 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -577,20 +577,11 @@ namespace libtorrent // peer potentially across you changing your IP. void set_key(int key); -#ifdef _MSC_VER -#pragma warning(push, 1) -#pragma warning(disable : 4268) -#endif - // built-in peer classes static constexpr peer_class_t global_peer_class_id{0}; static constexpr peer_class_t tcp_peer_class_id{1}; static constexpr peer_class_t local_peer_class_id{2}; -#ifdef _MSC_VER -#pragma warning(pop) -#endif - // ``is_listening()`` will tell you whether or not the session has // successfully opened a listening port. If it hasn't, this function will // return false, and then you can set a new diff --git a/include/libtorrent/torrent_status.hpp b/include/libtorrent/torrent_status.hpp index 7362eb303..dbde6be93 100644 --- a/include/libtorrent/torrent_status.hpp +++ b/include/libtorrent/torrent_status.hpp @@ -128,11 +128,6 @@ namespace libtorrent file_index_t error_file = torrent_status::error_file_none; -#ifdef _MSC_VER -#pragma warning(push, 1) -#pragma warning(disable : 4268) -#endif - // special values for error_file to describe which file or component // encountered the error (``errc``). // the error did not occur on a file @@ -152,10 +147,6 @@ namespace libtorrent // or a torrent log alert may provide more information. static constexpr file_index_t error_file_exception{-5}; -#ifdef _MSC_VER -#pragma warning(pop) -#endif - // the path to the directory where this torrent's files are stored. // It's typically the path as was given to async_add_torrent() or // add_torrent() when this torrent was started. This field is only diff --git a/include/libtorrent/units.hpp b/include/libtorrent/units.hpp index 672ca31ad..63fc435b8 100644 --- a/include/libtorrent/units.hpp +++ b/include/libtorrent/units.hpp @@ -58,7 +58,7 @@ namespace aux { strong_typedef() = default; #ifndef TORRENT_NO_DEPRECATE constexpr strong_typedef(UnderlyingType val) : m_val(val) {} - operator UnderlyingType() const { return m_val; } + constexpr operator UnderlyingType() const { return m_val; } #else constexpr explicit strong_typedef(UnderlyingType val) : m_val(val) {} constexpr explicit operator UnderlyingType() const { return m_val; }