diff --git a/include/libtorrent/add_torrent_params.hpp b/include/libtorrent/add_torrent_params.hpp index 6e1d7246d..d0d8c5e13 100644 --- a/include/libtorrent/add_torrent_params.hpp +++ b/include/libtorrent/add_torrent_params.hpp @@ -77,7 +77,7 @@ namespace libtorrent // The constructor can be used to initialize the storage constructor, // which determines the storage mechanism for the downloaded or seeding // data for the torrent. For more information, see the ``storage`` field. - add_torrent_params(storage_constructor_type sc = default_storage_constructor) + explicit add_torrent_params(storage_constructor_type sc = default_storage_constructor) : version(LIBTORRENT_VERSION_NUM) , storage_mode(storage_mode_sparse) , storage(sc) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 917c098c6..ec20340ee 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -1674,7 +1674,7 @@ namespace libtorrent struct TORRENT_EXPORT dht_bootstrap_alert final : alert { // internal - dht_bootstrap_alert(aux::stack_allocator& alloc); + explicit dht_bootstrap_alert(aux::stack_allocator& alloc); TORRENT_DEFINE_ALERT(dht_bootstrap_alert, 62) diff --git a/include/libtorrent/announce_entry.hpp b/include/libtorrent/announce_entry.hpp index 866aa19e4..cd324d4e5 100644 --- a/include/libtorrent/announce_entry.hpp +++ b/include/libtorrent/announce_entry.hpp @@ -47,7 +47,7 @@ namespace libtorrent struct TORRENT_EXPORT announce_entry { // constructs a tracker announce entry with ``u`` as the URL. - announce_entry(std::string u); + explicit announce_entry(std::string u); announce_entry(); ~announce_entry(); announce_entry(announce_entry const&) = default; diff --git a/include/libtorrent/aux_/bind_to_device.hpp b/include/libtorrent/aux_/bind_to_device.hpp index 2a1742831..e141f460e 100644 --- a/include/libtorrent/aux_/bind_to_device.hpp +++ b/include/libtorrent/aux_/bind_to_device.hpp @@ -47,7 +47,7 @@ namespace libtorrent { namespace aux { struct bind_to_device { - bind_to_device(char const* device): m_value(device) {} + explicit bind_to_device(char const* device): m_value(device) {} template int level(Protocol const&) const { return SOL_SOCKET; } template @@ -66,7 +66,7 @@ namespace libtorrent { namespace aux { struct bind_to_device { - bind_to_device(char const* device): m_value(if_nametoindex(device)) {} + explicit bind_to_device(char const* device): m_value(if_nametoindex(device)) {} template int level(Protocol const&) const { return IPPROTO_IP; } template @@ -85,7 +85,7 @@ namespace libtorrent { namespace aux { struct bind_to_device { - bind_to_device(char const* device): m_value(device) {} + explicit bind_to_device(char const* device): m_value(device) {} template int level(Protocol const&) const { return SOL_SOCKET; } template diff --git a/include/libtorrent/aux_/has_block.hpp b/include/libtorrent/aux_/has_block.hpp index 983532711..eac64abdc 100644 --- a/include/libtorrent/aux_/has_block.hpp +++ b/include/libtorrent/aux_/has_block.hpp @@ -40,7 +40,7 @@ namespace libtorrent { namespace aux { { has_block(has_block const&) = default; - has_block(piece_block const& b): block(b) {} + explicit has_block(piece_block const& b): block(b) {} bool operator()(pending_block const& pb) const { return pb.block == block; } private: diff --git a/include/libtorrent/aux_/proxy_settings.hpp b/include/libtorrent/aux_/proxy_settings.hpp index 91fffa006..de17a4eea 100644 --- a/include/libtorrent/aux_/proxy_settings.hpp +++ b/include/libtorrent/aux_/proxy_settings.hpp @@ -53,8 +53,8 @@ namespace aux { // construct the proxy_settings object from the settings // this constructor is implemented in session_impl.cpp - proxy_settings(settings_pack const& sett); - proxy_settings(aux::session_settings const& sett); + explicit proxy_settings(settings_pack const& sett); + explicit proxy_settings(aux::session_settings const& sett); // the name or IP of the proxy server. ``port`` is the port number the // proxy listens to. If required, ``username`` and ``password`` can be diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 2df5b88cc..8d66c5c78 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -216,7 +216,7 @@ namespace libtorrent typedef std::set> connection_map; typedef std::unordered_map> torrent_map; - session_impl(io_service& ios); + explicit session_impl(io_service& ios); virtual ~session_impl(); void start_session(settings_pack pack); @@ -1238,7 +1238,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING struct tracker_logger : request_callback { - tracker_logger(session_interface& ses); + explicit tracker_logger(session_interface& ses); void tracker_warning(tracker_request const& req , std::string const& str); void tracker_response(tracker_request const& diff --git a/include/libtorrent/bandwidth_manager.hpp b/include/libtorrent/bandwidth_manager.hpp index e9b70c72a..37dd90b16 100644 --- a/include/libtorrent/bandwidth_manager.hpp +++ b/include/libtorrent/bandwidth_manager.hpp @@ -47,7 +47,7 @@ namespace libtorrent { struct TORRENT_EXTRA_EXPORT bandwidth_manager { - bandwidth_manager(int channel); + explicit bandwidth_manager(int channel); void close(); @@ -57,7 +57,7 @@ struct TORRENT_EXTRA_EXPORT bandwidth_manager int queue_size() const; std::int64_t queued_bytes() const; - + // non prioritized means that, if there's a line for bandwidth, // others will cut in front of the non-prioritized peers. // this is used by web seeds diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 39004db44..9e9adad50 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -57,7 +57,7 @@ namespace libtorrent // from the specified buffer, and ``bits`` number of bits (rounded up to // the nearest byte boundary). bitfield() = default; - bitfield(int bits) { resize(bits); } + explicit bitfield(int bits) { resize(bits); } bitfield(int bits, bool val) { resize(bits, val); } bitfield(char const* b, int bits) { assign(b, bits); } bitfield(bitfield const& rhs) { assign(rhs.data(), rhs.size()); } diff --git a/include/libtorrent/block_cache.hpp b/include/libtorrent/block_cache.hpp index 43dc89b50..ab3ec947d 100644 --- a/include/libtorrent/block_cache.hpp +++ b/include/libtorrent/block_cache.hpp @@ -73,7 +73,7 @@ namespace libtorrent struct piece_log_t { - piece_log_t(int j, int b= -1): job(j), block(b) {} + explicit piece_log_t(int j, int b= -1): job(j), block(b) {} int job; int block; diff --git a/include/libtorrent/broadcast_socket.hpp b/include/libtorrent/broadcast_socket.hpp index 24402461e..a4583a73e 100644 --- a/include/libtorrent/broadcast_socket.hpp +++ b/include/libtorrent/broadcast_socket.hpp @@ -60,7 +60,7 @@ namespace libtorrent class TORRENT_EXTRA_EXPORT broadcast_socket { public: - broadcast_socket(udp::endpoint const& multicast_endpoint); + explicit broadcast_socket(udp::endpoint const& multicast_endpoint); ~broadcast_socket() { close(); } void open(receive_handler_t const& handler, io_service& ios @@ -77,7 +77,7 @@ namespace libtorrent struct socket_entry { - socket_entry(std::shared_ptr const& s) + explicit socket_entry(std::shared_ptr const& s) : socket(s), broadcast(false) { std::memset(buffer, 0, sizeof(buffer)); } socket_entry(std::shared_ptr const& s , address_v4 const& mask): socket(s), netmask(mask), broadcast(false) diff --git a/include/libtorrent/buffer.hpp b/include/libtorrent/buffer.hpp index 36442e98e..8e26895d6 100644 --- a/include/libtorrent/buffer.hpp +++ b/include/libtorrent/buffer.hpp @@ -62,7 +62,7 @@ class buffer public: // allocate an uninitialized buffer of the specified size - buffer(std::size_t size = 0) + explicit buffer(std::size_t size = 0) { TORRENT_ASSERT(size < std::size_t((std::numeric_limits::max)())); diff --git a/include/libtorrent/copy_ptr.hpp b/include/libtorrent/copy_ptr.hpp index 084f41a64..73c0d2e2b 100644 --- a/include/libtorrent/copy_ptr.hpp +++ b/include/libtorrent/copy_ptr.hpp @@ -39,7 +39,7 @@ namespace libtorrent struct copy_ptr { copy_ptr(): m_ptr(0) {} - copy_ptr(T* t): m_ptr(t) {} + explicit copy_ptr(T* t): m_ptr(t) {} copy_ptr(copy_ptr const& p): m_ptr(p.m_ptr ? new T(*p.m_ptr) : 0) {} void reset(T* t = 0) { delete m_ptr; m_ptr = t; } copy_ptr& operator=(copy_ptr const& p) diff --git a/include/libtorrent/create_torrent.hpp b/include/libtorrent/create_torrent.hpp index d319fdb19..ae4683073 100644 --- a/include/libtorrent/create_torrent.hpp +++ b/include/libtorrent/create_torrent.hpp @@ -171,7 +171,7 @@ namespace libtorrent explicit create_torrent(file_storage& fs, int piece_size = 0 , int pad_file_limit = -1, int flags = optimize_alignment , int alignment = -1); - create_torrent(torrent_info const& ti); + explicit create_torrent(torrent_info const& ti); // internal ~create_torrent(); diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index 0b6474ef9..89c3ff9c3 100644 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -109,14 +109,14 @@ namespace libtorrent // as a key, sorting would become a problem (e.g. to compare a string // to a list). The definition doesn't mention such a limit though. #if __cplusplus <= 201103 - typedef std::map dictionary_type; + using dictionary_type = std::map; #else - typedef std::map dictionary_type; + using dictionary_type = std::map; #endif - typedef std::string string_type; - typedef std::vector list_type; - typedef std::int64_t integer_type; - typedef std::vector preformatted_type; + using string_type = std::string; + using list_type = std::vector; + using integer_type = std::int64_t; + using preformatted_type = std::vector; // the types an entry can have enum data_type @@ -135,13 +135,13 @@ namespace libtorrent // constructors directly from a specific type. // The content of the argument is copied into the // newly constructed entry - entry(dictionary_type); - entry(span); + entry(dictionary_type); // NOLINT + entry(span); // NOLINT template ::value || std::is_same::value || std::is_same::value>::type> - entry(U v) + entry(U v) // NOLINT : m_type(undefined_t) { #if TORRENT_USE_ASSERTS @@ -150,13 +150,13 @@ namespace libtorrent new(&data) string_type(std::move(v)); m_type = string_t; } - entry(list_type); - entry(integer_type); - entry(preformatted_type); + entry(list_type); // NOLINT + entry(integer_type); // NOLINT + entry(preformatted_type); // NOLINT // construct an empty entry of the specified type. // see data_type enum. - entry(data_type t); + entry(data_type t); // NOLINT // hidden entry(entry const& e); diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index 3e467e8d4..c57fdd31f 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -500,7 +500,7 @@ namespace libtorrent struct TORRENT_EXPORT storage_error { storage_error(): file(-1), operation(0) {} - storage_error(error_code e): ec(e), file(-1), operation(0) {} + explicit storage_error(error_code e): ec(e), file(-1), operation(0) {} operator bool() const { return ec.value() != 0; } diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index b0b693672..7e4ba26f6 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -209,7 +209,7 @@ namespace libtorrent struct file_handle { file_handle(); - file_handle(file* f); + explicit file_handle(file* f); file_handle(file_handle const& fh); ~file_handle(); file* operator->(); diff --git a/include/libtorrent/file_pool.hpp b/include/libtorrent/file_pool.hpp index 85c2cd723..99cf58338 100644 --- a/include/libtorrent/file_pool.hpp +++ b/include/libtorrent/file_pool.hpp @@ -84,7 +84,7 @@ namespace libtorrent { // ``size`` specifies the number of allowed files handles // to hold open at any given time. - file_pool(int size = 40); + explicit file_pool(int size = 40); ~file_pool(); // return an open file handle to file at ``file_index`` in the diff --git a/include/libtorrent/hasher.hpp b/include/libtorrent/hasher.hpp index 34bdb1f6e..fd3bfcf1e 100644 --- a/include/libtorrent/hasher.hpp +++ b/include/libtorrent/hasher.hpp @@ -89,7 +89,7 @@ namespace libtorrent // this is the same as default constructing followed by a call to // ``update(data, len)``. hasher(char const* data, int len); - hasher(span data); + explicit hasher(span data); hasher(hasher const&); hasher& operator=(hasher const&); diff --git a/include/libtorrent/heterogeneous_queue.hpp b/include/libtorrent/heterogeneous_queue.hpp index 170adedd3..2614e06a1 100644 --- a/include/libtorrent/heterogeneous_queue.hpp +++ b/include/libtorrent/heterogeneous_queue.hpp @@ -158,7 +158,7 @@ namespace libtorrent { void (*move)(uintptr_t* dst, uintptr_t* src); }; - const static int header_size = (sizeof(header_t) + sizeof(uintptr_t) + static int const header_size = (sizeof(header_t) + sizeof(uintptr_t) - 1) / sizeof(uintptr_t); void grow_capacity(int const size) diff --git a/include/libtorrent/http_parser.hpp b/include/libtorrent/http_parser.hpp index 2ab632543..2736f6fee 100644 --- a/include/libtorrent/http_parser.hpp +++ b/include/libtorrent/http_parser.hpp @@ -58,7 +58,7 @@ namespace libtorrent { public: enum flags_t { dont_parse_chunks = 1 }; - http_parser(int flags = 0); + explicit http_parser(int flags = 0); ~http_parser(); std::string const& header(char const* key) const { diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index a699ff304..1f7826820 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -167,7 +167,7 @@ private: class i2p_connection { public: - i2p_connection(io_service& ios); + explicit i2p_connection(io_service& ios); ~i2p_connection(); aux::proxy_settings proxy() const; diff --git a/include/libtorrent/invariant_check.hpp b/include/libtorrent/invariant_check.hpp index 7859b7fb4..2bbbf15ce 100644 --- a/include/libtorrent/invariant_check.hpp +++ b/include/libtorrent/invariant_check.hpp @@ -35,7 +35,7 @@ namespace libtorrent template struct invariant_checker_impl : invariant_checker { - invariant_checker_impl(T const& self_) + explicit invariant_checker_impl(T const& self_) : self(self_) { TORRENT_TRY diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp index c83936b54..41dd4b29e 100644 --- a/include/libtorrent/ip_filter.hpp +++ b/include/libtorrent/ip_filter.hpp @@ -145,8 +145,8 @@ namespace detail TORRENT_ASSERT(!m_access_list.empty()); TORRENT_ASSERT(first < last || first == last); - typename range_t::iterator i = m_access_list.upper_bound(first); - typename range_t::iterator j = m_access_list.upper_bound(last); + auto i = m_access_list.upper_bound(first); + auto j = m_access_list.upper_bound(last); if (i != m_access_list.begin()) --i; @@ -198,7 +198,7 @@ namespace detail std::uint32_t access(Addr const& addr) const { TORRENT_ASSERT(!m_access_list.empty()); - typename range_t::const_iterator i = m_access_list.upper_bound(addr); + auto i = m_access_list.upper_bound(addr); if (i != m_access_list.begin()) --i; TORRENT_ASSERT(i != m_access_list.end()); TORRENT_ASSERT(i->start <= addr && (std::next(i) == m_access_list.end() @@ -234,20 +234,17 @@ namespace detail struct range { - range(Addr addr, int a = 0): start(addr), access(a) {} - bool operator<(range const& r) const - { return start < r.start; } - bool operator<(Addr const& a) const - { return start < a; } + range(Addr addr, int a = 0): start(addr), access(a) {} // NOLINT + bool operator<(range const& r) const { return start < r.start; } + bool operator<(Addr const& a) const { return start < a; } Addr start; // the end of the range is implicit // and given by the next entry in the set std::uint32_t access; }; - typedef std::set range_t; + using range_t = std::set; range_t m_access_list; - }; } diff --git a/include/libtorrent/kademlia/item.hpp b/include/libtorrent/kademlia/item.hpp index b3dd416ec..65af4060d 100644 --- a/include/libtorrent/kademlia/item.hpp +++ b/include/libtorrent/kademlia/item.hpp @@ -77,13 +77,13 @@ class TORRENT_EXTRA_EXPORT item public: item() : m_seq(0), m_mutable(false) {} item(public_key const& pk, span salt); - item(entry v); + explicit item(entry v); item(entry v , span salt , sequence_number seq , public_key const& pk , secret_key const& sk); - item(bdecode_node const& v); + explicit item(bdecode_node const& v); void assign(entry v); void assign(entry v, span salt diff --git a/include/libtorrent/kademlia/node_entry.hpp b/include/libtorrent/kademlia/node_entry.hpp index f838cd2ec..5988e6430 100644 --- a/include/libtorrent/kademlia/node_entry.hpp +++ b/include/libtorrent/kademlia/node_entry.hpp @@ -46,7 +46,7 @@ struct TORRENT_EXTRA_EXPORT node_entry { node_entry(node_id const& id_, udp::endpoint const& ep, int roundtriptime = 0xffff , bool pinged = false); - node_entry(udp::endpoint const& ep); + explicit node_entry(udp::endpoint const& ep); node_entry(); void update_rtt(int new_rtt); diff --git a/include/libtorrent/linked_list.hpp b/include/libtorrent/linked_list.hpp index 9b303f169..cffca27c8 100644 --- a/include/libtorrent/linked_list.hpp +++ b/include/libtorrent/linked_list.hpp @@ -57,7 +57,7 @@ namespace libtorrent void prev() { m_current = m_current->prev; } private: - list_iterator(T* cur) + explicit list_iterator(T* cur) : m_current(cur) {} // the current element T* m_current; diff --git a/include/libtorrent/peer_class.hpp b/include/libtorrent/peer_class.hpp index e196ce7d9..1333d2c9d 100644 --- a/include/libtorrent/peer_class.hpp +++ b/include/libtorrent/peer_class.hpp @@ -86,7 +86,7 @@ namespace libtorrent { friend struct peer_class_pool; - peer_class(std::string const& l) + explicit peer_class(std::string const& l) : ignore_unchoke_slots(false) , connection_limit_factor(100) , label(l) diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index d034fc449..0e3976584 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -92,7 +92,7 @@ namespace libtorrent struct pending_block { - pending_block(piece_block const& b) + pending_block(piece_block const& b) // NOLINT : block(b), send_buffer_offset(not_in_buffer), not_wanted(false) , timed_out(false), busy(false) {} @@ -277,7 +277,7 @@ namespace libtorrent num_channels }; - peer_connection(peer_connection_args const& pack); + explicit peer_connection(peer_connection_args const& pack); // this function is called after it has been constructed and properly // reference counted. It is safe to call self() in this function @@ -1216,7 +1216,7 @@ namespace libtorrent struct cork { - cork(peer_connection& p): m_pc(p), m_need_uncork(false) + explicit cork(peer_connection& p): m_pc(p) { if (m_pc.is_corked()) return; m_pc.cork_socket(); @@ -1225,7 +1225,7 @@ namespace libtorrent ~cork() { if (m_need_uncork) m_pc.uncork_socket(); } private: peer_connection& m_pc; - bool m_need_uncork; + bool m_need_uncork = false; cork& operator=(cork const&); }; diff --git a/include/libtorrent/peer_connection_handle.hpp b/include/libtorrent/peer_connection_handle.hpp index 2e5d9760f..6d55fdee3 100644 --- a/include/libtorrent/peer_connection_handle.hpp +++ b/include/libtorrent/peer_connection_handle.hpp @@ -51,7 +51,7 @@ struct crypto_plugin; struct TORRENT_EXPORT peer_connection_handle { - peer_connection_handle(std::weak_ptr impl) + explicit peer_connection_handle(std::weak_ptr impl) : m_connection(impl) {} diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 241f1cf8c..598a2a2b1 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -418,7 +418,7 @@ namespace libtorrent // functor that compares indices on downloading_pieces struct has_index { - has_index(int i): index(std::uint32_t(i)) { TORRENT_ASSERT(i >= 0); } + explicit has_index(int i): index(std::uint32_t(i)) { TORRENT_ASSERT(i >= 0); } bool operator()(const downloading_piece& p) const { return p.index == index; } std::uint32_t index; diff --git a/include/libtorrent/receive_buffer.hpp b/include/libtorrent/receive_buffer.hpp index 3c30f132f..72f40b96d 100644 --- a/include/libtorrent/receive_buffer.hpp +++ b/include/libtorrent/receive_buffer.hpp @@ -167,7 +167,7 @@ private: // tracks the state of the bittorrent protocol. struct crypto_receive_buffer { - crypto_receive_buffer(receive_buffer& next) + explicit crypto_receive_buffer(receive_buffer& next) : m_connection_buffer(next) {} diff --git a/include/libtorrent/resolve_links.hpp b/include/libtorrent/resolve_links.hpp index df3649432..5ed1109ae 100644 --- a/include/libtorrent/resolve_links.hpp +++ b/include/libtorrent/resolve_links.hpp @@ -57,7 +57,7 @@ namespace libtorrent int file_idx; }; - resolve_links(std::shared_ptr ti); + explicit resolve_links(std::shared_ptr ti); // check to see if any files are shared with this torrent void match(std::shared_ptr const& ti diff --git a/include/libtorrent/resolver.hpp b/include/libtorrent/resolver.hpp index 1718f9e84..d4d53b305 100644 --- a/include/libtorrent/resolver.hpp +++ b/include/libtorrent/resolver.hpp @@ -55,7 +55,7 @@ namespace libtorrent struct TORRENT_EXTRA_EXPORT resolver final : resolver_interface { - resolver(io_service& ios); + explicit resolver(io_service& ios); virtual void async_resolve(std::string const& host, int flags , callback_t const& h) override; diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 6fc346dc4..4cd28ea67 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -133,7 +133,7 @@ namespace libtorrent // (ut_metadata, ut_pex and smart_ban). The default values in the // settings is to start the default features like upnp, nat-pmp, // and dht for example. - session_params(settings_pack sp = settings_pack()); + explicit session_params(settings_pack sp = settings_pack()); // This constructor helps to configure the set of initial plugins // to be added to the session before it's started. session_params(settings_pack sp @@ -180,7 +180,7 @@ namespace libtorrent // In order to avoid a race condition between starting the session and // configuring it, you can pass in a session_params object. Its settings // will take effect before the session starts up. - session(session_params params = session_params()) + explicit session(session_params params = session_params()) : session_handle(nullptr) { TORRENT_CFG(); diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index bef79b20b..0e5c4b0c1 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -69,7 +69,7 @@ namespace libtorrent { session_handle() : m_impl(nullptr) {} - session_handle(aux::session_impl* impl) + explicit session_handle(aux::session_impl* impl) : m_impl(impl) {} diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index c7b62a9cf..8ac85c24d 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -94,7 +94,7 @@ namespace libtorrent struct v6_protection_level { - v6_protection_level(int level): m_value(level) {} + explicit v6_protection_level(int level): m_value(level) {} template int level(Protocol const&) const { return IPPROTO_IPV6; } template @@ -108,7 +108,7 @@ namespace libtorrent struct exclusive_address_use { - exclusive_address_use(int enable): m_value(enable) {} + explicit exclusive_address_use(int enable): m_value(enable) {} template int level(Protocol const&) const { return SOL_SOCKET; } template @@ -124,7 +124,7 @@ namespace libtorrent #ifdef IPV6_TCLASS struct traffic_class { - traffic_class(char val): m_value(val) {} + explicit traffic_class(char val): m_value(val) {} template int level(Protocol const&) const { return IPPROTO_IPV6; } template @@ -140,11 +140,11 @@ namespace libtorrent struct type_of_service { #ifdef _WIN32 - typedef DWORD tos_t; + using tos_t = DWORD; #else - typedef int tos_t; + using tos_t = int; #endif - type_of_service(char val): m_value(val) {} + explicit type_of_service(char val): m_value(val) {} template int level(Protocol const&) const { return IPPROTO_IP; } template @@ -163,7 +163,7 @@ namespace libtorrent #ifdef TORRENT_HAS_DONT_FRAGMENT struct dont_fragment { - dont_fragment(bool val) + explicit dont_fragment(bool val) #ifdef IP_PMTUDISCOVER_DO : m_value(val ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT) {} #else diff --git a/include/libtorrent/span.hpp b/include/libtorrent/span.hpp index e7bc5ccfa..812a3ee9c 100644 --- a/include/libtorrent/span.hpp +++ b/include/libtorrent/span.hpp @@ -46,23 +46,23 @@ namespace libtorrent span() : m_ptr(nullptr), m_len(0) {} template - span(span const& v) + span(span const& v) // NOLINT : m_ptr(v.data()), m_len(v.size()) {} - span(T& p) : m_ptr(&p), m_len(1) {} - span(T* p, size_t const l) : m_ptr(p), m_len(l) {} + span(T& p) : m_ptr(&p), m_len(1) {} // NOLINT + span(T* p, size_t const l) : m_ptr(p), m_len(l) {} // NOLINT template - span(std::array& arr) + span(std::array& arr) // NOLINT : m_ptr(arr.data()), m_len(arr.size()) {} template - span(U (&arr)[N]) + span(U (&arr)[N]) // NOLINT : m_ptr(&arr[0]), m_len(N) {} // anything with a .data() member function is considered a container template ().data())> - span(Cont& c) + span(Cont& c) // NOLINT : m_ptr(c.data()), m_len(c.size()) {} size_t size() const { return m_len; } diff --git a/include/libtorrent/stat_cache.hpp b/include/libtorrent/stat_cache.hpp index b5d82906a..834fda909 100644 --- a/include/libtorrent/stat_cache.hpp +++ b/include/libtorrent/stat_cache.hpp @@ -78,7 +78,7 @@ namespace libtorrent struct stat_cache_t { - stat_cache_t(std::int64_t s): file_size(s) {} + stat_cache_t(std::int64_t s): file_size(s) {} // NOLINT // the size of the file. Negative values have special meaning. -1 means // not-in-cache (i.e. there's no data for this file in the cache). diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 20145bedd..5d1c0a730 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -388,7 +388,7 @@ namespace libtorrent // an empty vector. Any file whose index is not represented by the vector // (because the vector is too short) are assumed to have priority 1. // this is used to treat files with priority 0 slightly differently. - default_storage(storage_params const& params); + explicit default_storage(storage_params const& params); // hidden ~default_storage(); diff --git a/include/libtorrent/tailqueue.hpp b/include/libtorrent/tailqueue.hpp index 41bc89cfd..260342158 100644 --- a/include/libtorrent/tailqueue.hpp +++ b/include/libtorrent/tailqueue.hpp @@ -61,7 +61,7 @@ namespace libtorrent void next() { m_current = m_current->next; } private: - tailqueue_iterator(T* cur) + explicit tailqueue_iterator(T* cur) : m_current(cur) {} // the current element T* m_current; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index c4f62aa5f..f09d4b071 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -126,7 +126,7 @@ namespace libtorrent // this is the internal representation of web seeds struct web_seed_t : web_seed_entry { - web_seed_t(web_seed_entry const& wse); + explicit web_seed_t(web_seed_entry const& wse); web_seed_t(std::string const& url_, web_seed_entry::type_t type_ , std::string const& auth_ = std::string() , web_seed_entry::headers_t const& extra_headers_ = web_seed_entry::headers_t()); diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index ba94a6826..85d9fb1a6 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -1293,7 +1293,7 @@ namespace libtorrent template Ret sync_call_ret(Ret def, Fun f, Args&&... a) const; - torrent_handle(std::weak_ptr const& t) + explicit torrent_handle(std::weak_ptr const& t) { if (!t.expired()) m_torrent = t; } std::weak_ptr m_torrent; diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index a3dd31b7d..709f03fe0 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -383,7 +383,7 @@ namespace libtorrent // ------- start deprecation ------- // these functions will be removed in a future version TORRENT_DEPRECATED - torrent_info(entry const& torrent_file); + explicit torrent_info(entry const& torrent_file); // ------- end deprecation ------- #endif diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 390cbb68c..c2661adde 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -250,7 +250,7 @@ namespace libtorrent : std::enable_shared_from_this , boost::noncopyable { - timeout_handler(io_service& str); + explicit timeout_handler(io_service& str); void set_timeout(int completion_timeout, int read_timeout); void restart_read_timeout(); diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index 697b02023..a6d074544 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -50,7 +50,7 @@ namespace libtorrent class TORRENT_EXTRA_EXPORT udp_socket : single_threaded { public: - udp_socket(io_service& ios); + explicit udp_socket(io_service& ios); enum flags_t { peer_connection = 1 diff --git a/include/libtorrent/union_endpoint.hpp b/include/libtorrent/union_endpoint.hpp index 08a314d09..0f236e181 100644 --- a/include/libtorrent/union_endpoint.hpp +++ b/include/libtorrent/union_endpoint.hpp @@ -40,16 +40,8 @@ namespace libtorrent { struct union_address { - union_address() - { - *this = address(); - } - - union_address(address const& a) - { - *this = a; - } - + union_address() { *this = address(); } + explicit union_address(address const& a) { *this = a; } union_address& operator=(address const& a) { #if TORRENT_USE_IPV6 @@ -106,20 +98,9 @@ namespace libtorrent struct union_endpoint { - union_endpoint(tcp::endpoint const& ep) - { - *this = ep; - } - - union_endpoint(udp::endpoint const& ep) - { - *this = ep; - } - - union_endpoint() - { - *this = tcp::endpoint(); - } + explicit union_endpoint(tcp::endpoint const& ep) { *this = ep; } + explicit union_endpoint(udp::endpoint const& ep) { *this = ep; } + union_endpoint() { *this = tcp::endpoint(); } union_endpoint& operator=(udp::endpoint const& ep) { @@ -128,10 +109,7 @@ namespace libtorrent return *this; } - operator udp::endpoint() const - { - return udp::endpoint(addr, port); - } + operator udp::endpoint() const { return udp::endpoint(addr, port); } union_endpoint& operator=(tcp::endpoint const& ep) { @@ -140,15 +118,8 @@ namespace libtorrent return *this; } - libtorrent::address address() const - { - return addr; - } - - operator tcp::endpoint() const - { - return tcp::endpoint(addr, port); - } + libtorrent::address address() const { return addr; } + operator tcp::endpoint() const { return tcp::endpoint(addr, port); } union_address addr; std::uint16_t port; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 6108f9340..9f4e5844f 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -2521,7 +2521,7 @@ namespace libtorrent // if we're disconnecting, we shouldn't add pieces if (!in_req_queue && !m_disconnecting) { - for (std::vector::iterator i = m_request_queue.begin() + for (auto i = m_request_queue.begin() , end(m_request_queue.end()); i != end; ++i) { if (i->block != b) continue; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index f94c24166..4c5fd077d 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include // for snprintf #include // for PRId64 et.al. #include @@ -82,7 +81,6 @@ const rlim_t rlim_infinity = RLIM_INFINITY; #include "libtorrent/kademlia/node_entry.hpp" #endif #include "libtorrent/enum_net.hpp" -#include "libtorrent/config.hpp" #include "libtorrent/utf8.hpp" #include "libtorrent/upnp.hpp" #include "libtorrent/natpmp.hpp" @@ -382,7 +380,8 @@ namespace aux { SSL_CTX *torrent_context = t->ssl_ctx()->native_handle(); SSL_set_SSL_CTX(s, torrent_context); - SSL_set_verify(s, SSL_CTX_get_verify_mode(torrent_context), SSL_CTX_get_verify_callback(torrent_context)); + SSL_set_verify(s, SSL_CTX_get_verify_mode(torrent_context) + , SSL_CTX_get_verify_callback(torrent_context)); return SSL_TLSEXT_ERR_OK; } @@ -592,11 +591,13 @@ namespace aux { #endif m_io_service.post([this]{ this->wrap(&session_impl::on_tick, error_code()); }); + int const lsd_announce_interval + = m_settings.get_int(settings_pack::local_service_announce_interval); + int const delay = std::max(lsd_announce_interval + / std::max(static_cast(m_torrents.size()), 1), 1); error_code ec; - ADD_OUTSTANDING_ASYNC("session_impl::on_lsd_announce"); - int const delay = std::max(m_settings.get_int(settings_pack::local_service_announce_interval) - / std::max(int(m_torrents.size()), 1), 1); m_lsd_announce_timer.expires_from_now(seconds(delay), ec); + ADD_OUTSTANDING_ASYNC("session_impl::on_lsd_announce"); m_lsd_announce_timer.async_wait([this](error_code const& e) { this->wrap(&session_impl::on_lsd_announce, e); } ); TORRENT_ASSERT(!ec); diff --git a/src/torrent.cpp b/src/torrent.cpp index 68ace0e07..6512a88b4 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -294,8 +294,9 @@ namespace libtorrent int tier = 0; auto tier_iter = p.tracker_tiers.begin(); - for (announce_entry e : p.trackers) + for (auto const& url : p.trackers) { + announce_entry e(url); if (tier_iter != p.tracker_tiers.end()) tier = *tier_iter++; diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index ae7c173be..5bbcba528 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1347,9 +1347,8 @@ namespace libtorrent if (ec) return false; m_info_hash = p.info_hash; - for (std::vector::iterator i = p.trackers.begin() - , end(p.trackers.end()); i != end; ++i) - m_urls.push_back(*i); + for (auto const& url : p.trackers) + m_urls.push_back(announce_entry(url)); return true; } diff --git a/test/test_dht.cpp b/test/test_dht.cpp index e89168f31..df16c105e 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -1741,7 +1741,7 @@ void test_bootstrap(address(&rand_addr)()) udp::endpoint found_node(rand_addr(), 2235); std::vector nodes; - nodes.push_back(found_node); + nodes.push_back(node_entry{found_node}); g_sent_packets.clear(); if (initial_node.address().is_v4()) send_dht_response(t.dht_node, response, initial_node, msg_args().nodes(nodes)); @@ -1843,7 +1843,7 @@ void test_short_nodes(address(&rand_addr)()) udp::endpoint found_node(rand_addr(), 2235); std::vector nodes; - nodes.push_back(found_node); + nodes.push_back(node_entry{found_node}); g_sent_packets.clear(); msg_args args; // chop one byte off of the nodes string @@ -1900,7 +1900,7 @@ void test_get_peers(address(&rand_addr)()) dht::node_id const target = to_hash("1234876923549721020394873245098347598635"); udp::endpoint const initial_node(rand_addr(), 1234); - t.dht_node.m_table.add_node(initial_node); + t.dht_node.m_table.add_node(node_entry{initial_node}); t.dht_node.announce(target, 1234, false, get_peers_cb); @@ -1933,7 +1933,7 @@ void test_get_peers(address(&rand_addr)()) udp::endpoint next_node(rand_addr(), 2235); std::vector nodes; - nodes.push_back(next_node); + nodes.push_back(node_entry{next_node}); g_sent_packets.clear(); if (initial_node.address().is_v4()) @@ -2032,7 +2032,7 @@ void test_mutable_get(address(&rand_addr)(), bool const with_salt) g_sent_packets.clear(); udp::endpoint const initial_node(rand_addr(), 1234); - t.dht_node.m_table.add_node(initial_node); + t.dht_node.m_table.add_node(node_entry{initial_node}); g_put_item.assign(items[0].ent, salt, seq, pk, sk); t.dht_node.put_item(pk, std::string() @@ -2129,7 +2129,7 @@ TORRENT_TEST(immutable_get) g_sent_packets.clear(); udp::endpoint initial_node(addr4("4.4.4.4"), 1234); - t.dht_node.m_table.add_node(initial_node); + t.dht_node.m_table.add_node(node_entry{initial_node}); t.dht_node.get_item(items[0].target, get_immutable_item_cb); @@ -2960,7 +2960,7 @@ TORRENT_TEST(read_only_node) bdecode_node parsed[7]; char error_string[200]; udp::endpoint initial_node(addr("4.4.4.4"), 1234); - node.m_table.add_node(initial_node); + node.m_table.add_node(node_entry{initial_node}); bdecode_node request; sha1_hash target = generate_next(); diff --git a/test/test_storage.cpp b/test/test_storage.cpp index ecf07a55f..43c708d85 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -352,7 +352,7 @@ void test_remove(std::string const& test_path, bool unbuffered) TEST_EQUAL(st.file_size, 8); s->delete_files(session::delete_files, se); - if (se) print_error("delete_files", 0, se.ec); + if (se) print_error("delete_files", 0, se); if (se) {