diff --git a/examples/client_test.cpp b/examples/client_test.cpp index c1ebd9a7a..65d1fda7b 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -354,7 +354,7 @@ std::string print_endpoint(libtorrent::tcp::endpoint const& ep) struct torrent_entry { - torrent_entry(libtorrent::torrent_handle h) : handle(std::move(h)) {} + explicit torrent_entry(libtorrent::torrent_handle h) : handle(std::move(h)) {} libtorrent::torrent_handle handle; libtorrent::torrent_status status; }; diff --git a/simulation/setup_dht.cpp b/simulation/setup_dht.cpp index fa5b57a59..9563d5561 100644 --- a/simulation/setup_dht.cpp +++ b/simulation/setup_dht.cpp @@ -302,7 +302,7 @@ dht_network::dht_network(sim::simulation& sim, int num_nodes, std::uint32_t flag } } -dht_network::~dht_network() {} +dht_network::~dht_network() = default; void print_routing_table(std::vector const& rt) { diff --git a/src/bdecode.cpp b/src/bdecode.cpp index 145a663c9..f8a65bb42 100644 --- a/src/bdecode.cpp +++ b/src/bdecode.cpp @@ -102,7 +102,7 @@ namespace libtorrent struct stack_frame { - stack_frame(int const t): token(t), state(0) {} + explicit stack_frame(int const t): token(t), state(0) {} // this is an index into m_tokens std::uint32_t token:31; // this is used for dictionaries to indicate whether we're @@ -752,7 +752,7 @@ namespace libtorrent switch (t) { case 'd': - stack[sp++] = int(ret.m_tokens.size()); + stack[sp++] = stack_frame(int(ret.m_tokens.size())); // we push it into the stack so that we know where to fill // in the next_node field once we pop this node off the stack. // i.e. get to the node following the dictionary in the buffer @@ -761,7 +761,7 @@ namespace libtorrent ++start; break; case 'l': - stack[sp++] = int(ret.m_tokens.size()); + stack[sp++] = stack_frame(int(ret.m_tokens.size())); // we push it into the stack so that we know where to fill // in the next_node field once we pop this node off the stack. // i.e. get to the node following the list in the buffer diff --git a/src/http_connection.cpp b/src/http_connection.cpp index aa5bf2312..a8cc8df57 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -328,7 +328,7 @@ void http_connection::start(std::string const& hostname, int port #ifdef TORRENT_USE_OPENSSL if (m_ssl) { - if (m_ssl_ctx == 0) + if (m_ssl_ctx == nullptr) { m_ssl_ctx = new (std::nothrow) ssl::context( m_timer.get_io_service(), ssl::context::sslv23_client); diff --git a/src/kademlia/dht_storage.cpp b/src/kademlia/dht_storage.cpp index 5e78dcf84..8b9fabe40 100644 --- a/src/kademlia/dht_storage.cpp +++ b/src/kademlia/dht_storage.cpp @@ -89,7 +89,7 @@ namespace struct count_peers { int* count; - count_peers(int* c): count(c) {} + explicit count_peers(int* c): count(c) {} void operator()(std::pair const& t) { @@ -147,7 +147,7 @@ namespace // less important to keep struct immutable_item_comparator { - immutable_item_comparator(std::vector const& node_ids) : m_node_ids(node_ids) {} + explicit immutable_item_comparator(std::vector const& node_ids) : m_node_ids(node_ids) {} immutable_item_comparator(immutable_item_comparator const&) = default; bool operator() (std::pair const& lhs @@ -193,7 +193,7 @@ namespace public: - dht_default_storage(dht_settings const& settings) + explicit dht_default_storage(dht_settings const& settings) : m_settings(settings) { m_counters.reset(); diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 1f6d8d8f2..fa2be6a4e 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -353,7 +353,7 @@ namespace libtorrent { namespace dht struct get_immutable_item_ctx { - get_immutable_item_ctx(int traversals) + explicit get_immutable_item_ctx(int traversals) : active_traversals(traversals) , item_posted(false) {} @@ -379,7 +379,7 @@ namespace libtorrent { namespace dht struct get_mutable_item_ctx { - get_mutable_item_ctx(int traversals) : active_traversals(traversals) {} + explicit get_mutable_item_ctx(int traversals) : active_traversals(traversals) {} int active_traversals; item it; }; @@ -404,7 +404,7 @@ namespace libtorrent { namespace dht struct put_item_ctx { - put_item_ctx(int traversals) + explicit put_item_ctx(int traversals) : active_traversals(traversals) , response_count(0) {} diff --git a/src/lt_trackers.cpp b/src/lt_trackers.cpp index 250e79612..709490d66 100644 --- a/src/lt_trackers.cpp +++ b/src/lt_trackers.cpp @@ -73,7 +73,7 @@ namespace libtorrent { namespace struct lt_tracker_plugin : torrent_plugin { - lt_tracker_plugin(torrent& t) + explicit lt_tracker_plugin(torrent& t) : m_torrent(t) , m_updates(0) , m_2_minutes(110) diff --git a/src/metadata_transfer.cpp b/src/metadata_transfer.cpp index 2e5b914dc..2d25ec061 100644 --- a/src/metadata_transfer.cpp +++ b/src/metadata_transfer.cpp @@ -99,7 +99,7 @@ namespace libtorrent { namespace struct metadata_plugin final : torrent_plugin { - metadata_plugin(torrent& t) + explicit metadata_plugin(torrent& t) : m_torrent(t) , m_metadata_progress(0) , m_metadata_size(0) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index e6ed20d4a..4f14cd3b6 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -2568,7 +2568,7 @@ namespace libtorrent #if TORRENT_USE_INVARIANT_CHECKS struct check_postcondition { - check_postcondition(boost::shared_ptr const& t_ + explicit check_postcondition(boost::shared_ptr const& t_ , bool init_check = true): t(t_) { if (init_check) check(); } ~check_postcondition() { check(); } diff --git a/src/peer_list.cpp b/src/peer_list.cpp index 64a2f30a9..0db7c9918 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -71,7 +71,7 @@ namespace struct match_peer_endpoint { - match_peer_endpoint(tcp::endpoint const& ep) + explicit match_peer_endpoint(tcp::endpoint const& ep) : m_ep(ep) {} @@ -87,7 +87,7 @@ namespace #if TORRENT_USE_INVARIANT_CHECKS struct match_peer_connection { - match_peer_connection(peer_connection_interface const& c) : m_conn(c) {} + explicit match_peer_connection(peer_connection_interface const& c) : m_conn(c) {} bool operator()(torrent_peer const* p) const { @@ -102,7 +102,7 @@ namespace #if TORRENT_USE_ASSERTS struct match_peer_connection_or_endpoint { - match_peer_connection_or_endpoint(peer_connection_interface const& c) : m_conn(c) {} + explicit match_peer_connection_or_endpoint(peer_connection_interface const& c) : m_conn(c) {} bool operator()(torrent_peer const* p) const { diff --git a/src/session.cpp b/src/session.cpp index a3c7e4a18..cd3734b3d 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -403,7 +403,7 @@ namespace libtorrent , std::shared_ptr t , boost::shared_ptr impl) : m_io_service(std::move(ios)) - , m_thread(t) + , m_thread(std::move(t)) , m_impl(impl) {} session_proxy::session_proxy(session_proxy const&) = default; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index b58dc0064..6d072c3a4 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -776,7 +776,7 @@ namespace aux { struct session_plugin_wrapper : plugin { - session_plugin_wrapper(ext_function_t const& f) : m_f(f) {} + explicit session_plugin_wrapper(ext_function_t const& f) : m_f(f) {} boost::shared_ptr new_torrent(torrent_handle const& t, void* user) override { return m_f(t, user); } @@ -3736,7 +3736,7 @@ namespace aux { struct opt_unchoke_candidate { - opt_unchoke_candidate(boost::shared_ptr const* tp) + explicit opt_unchoke_candidate(boost::shared_ptr const* tp) : peer(tp) {} @@ -3752,7 +3752,7 @@ namespace aux { struct last_optimistic_unchoke_cmp { #ifndef TORRENT_DISABLE_EXTENSIONS - last_optimistic_unchoke_cmp(std::vector>& ps) + explicit last_optimistic_unchoke_cmp(std::vector>& ps) : plugins(ps) {} diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index 2e3a8ae79..0ae992217 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -76,7 +76,7 @@ namespace : torrent_plugin , boost::enable_shared_from_this { - smart_ban_plugin(torrent& t) + explicit smart_ban_plugin(torrent& t) : m_torrent(t) , m_salt(random()) {} diff --git a/src/socket_type.cpp b/src/socket_type.cpp index ee0078f1f..ca556961c 100644 --- a/src/socket_type.cpp +++ b/src/socket_type.cpp @@ -100,8 +100,8 @@ namespace libtorrent ctx = SSL_get_SSL_CTX(ssl); \ break; - SSL* ssl = 0; - SSL_CTX* ctx = 0; + SSL* ssl = nullptr; + SSL_CTX* ctx = nullptr; switch(s.type()) { @@ -115,8 +115,8 @@ namespace libtorrent #if OPENSSL_VERSION_NUMBER >= 0x90812f if (ctx) { - aux::openssl_set_tlsext_servername_callback(ctx, 0); - aux::openssl_set_tlsext_servername_arg(ctx, 0); + aux::openssl_set_tlsext_servername_callback(ctx, nullptr); + aux::openssl_set_tlsext_servername_arg(ctx, nullptr); } #endif // OPENSSL_VERSION_NUMBER diff --git a/src/torrent.cpp b/src/torrent.cpp index fdd9dd9af..590e9ff16 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1488,7 +1488,7 @@ namespace libtorrent // Go through the alternate names in the certificate looking for matching DNS entries GENERAL_NAMES* gens = static_cast( - X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0)); + X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, nullptr)); #ifndef TORRENT_DISABLE_LOGGING std::string names; @@ -1525,7 +1525,7 @@ namespace libtorrent // use the "most specific" common name, which is the last one in the list. X509_NAME* name = X509_get_subject_name(cert); int i = -1; - ASN1_STRING* common_name = 0; + ASN1_STRING* common_name = nullptr; while ((i = X509_NAME_get_index_by_NID(name, NID_commonName, i)) >= 0) { X509_NAME_ENTRY* name_entry = X509_NAME_get_entry(name, i); @@ -1637,7 +1637,7 @@ namespace libtorrent // parse the certificate into OpenSSL's internal // representation - X509* certificate = PEM_read_bio_X509_AUX(bp, 0, 0, 0); + X509* certificate = PEM_read_bio_X509_AUX(bp, nullptr, nullptr, nullptr); BIO_free(bp); @@ -7100,7 +7100,7 @@ namespace libtorrent ssl_conn = s->get >()->native_handle(); \ break; - SSL* ssl_conn = 0; + SSL* ssl_conn = nullptr; switch (s->type()) { @@ -7112,7 +7112,7 @@ namespace libtorrent #undef SSL - if (ssl_conn == 0) + if (ssl_conn == nullptr) { // don't allow non SSL peers on SSL torrents p->disconnect(errors::requires_ssl_connection, op_bittorrent); diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 073d75831..e60a1786c 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1539,7 +1539,7 @@ namespace libtorrent { struct filter_web_seed_type { - filter_web_seed_type(web_seed_entry::type_t t_) : t(t_) {} + explicit filter_web_seed_type(web_seed_entry::type_t t_) : t(t_) {} void operator() (web_seed_entry const& w) { if (w.type == t) urls.push_back(w.url); } std::vector urls; diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 80dc8afd8..db9783e45 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -74,7 +74,7 @@ using namespace std::placeholders; // the common case cheaper by not allocating this space unconditionally struct socks5 : boost::enable_shared_from_this { - socks5(io_service& ios) + explicit socks5(io_service& ios) : m_socks5_sock(ios) , m_resolver(ios) , m_timer(ios) diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index 68b8d5d00..3a23fc11e 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -95,7 +95,7 @@ namespace libtorrent { namespace struct ut_metadata_plugin final : torrent_plugin { - ut_metadata_plugin(torrent& t) + explicit ut_metadata_plugin(torrent& t) : m_torrent(t) // , m_metadata_progress(0) , m_metadata_size(0) diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 82a515d71..242e12eab 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -88,7 +88,7 @@ namespace libtorrent { namespace // to evenly spread it out across all torrents // the more torrents we have, the longer we can // delay the rebuilding - ut_pex_plugin(torrent& t) + explicit ut_pex_plugin(torrent& t) : m_torrent(t) , m_last_msg(min_time()) , m_peers_in_message(0) {} diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 30d78c928..59e744206 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -1723,7 +1723,7 @@ void utp_socket_impl::remove_sack_header(packet* p) struct holder { - holder(char* buf = nullptr): m_buf(buf) {} + explicit holder(char* buf = nullptr): m_buf(buf) {} ~holder() { free(m_buf); } void reset(char* buf) diff --git a/test/test_alert_manager.cpp b/test/test_alert_manager.cpp index 9e774d22b..0c9f8b023 100644 --- a/test/test_alert_manager.cpp +++ b/test/test_alert_manager.cpp @@ -156,7 +156,7 @@ int plugin_alerts[3] = { 0, 0, 0 }; struct test_plugin : libtorrent::plugin { - test_plugin(int index) : m_index(index) {} + explicit test_plugin(int index) : m_index(index) {} void on_alert(alert const* a) override { ++plugin_alerts[m_index]; diff --git a/test/test_heterogeneous_queue.cpp b/test/test_heterogeneous_queue.cpp index 5c376e65e..cb1d14e4c 100644 --- a/test/test_heterogeneous_queue.cpp +++ b/test/test_heterogeneous_queue.cpp @@ -69,7 +69,7 @@ struct D struct E { - E(char const* msg) : string_member(msg) {} + explicit E(char const* msg) : string_member(msg) {} std::string string_member; }; @@ -77,7 +77,7 @@ int D::instances = 0; struct F { - F(int f_) + explicit F(int f_) : self(this) , f(f_) , constructed(true) diff --git a/test/test_linked_list.cpp b/test/test_linked_list.cpp index 5ffb89d32..0e182da06 100644 --- a/test/test_linked_list.cpp +++ b/test/test_linked_list.cpp @@ -37,7 +37,7 @@ using namespace libtorrent; struct test_node : list_node { - test_node(int v) : val(v) {} + explicit test_node(int v) : val(v) {} int val; }; diff --git a/test/test_peer_list.cpp b/test/test_peer_list.cpp index 5b9bafdd6..5e2fe1a0e 100644 --- a/test/test_peer_list.cpp +++ b/test/test_peer_list.cpp @@ -113,7 +113,7 @@ struct mock_peer_connection struct mock_torrent { - mock_torrent(torrent_state* st) : m_p(nullptr), m_state(st) {} + explicit mock_torrent(torrent_state* st) : m_p(nullptr), m_state(st) {} virtual ~mock_torrent() = default; bool connect_to_peer(torrent_peer* peerinfo, bool ignore_limit = false) diff --git a/test/test_ssl.cpp b/test/test_ssl.cpp index b65a36071..2ca860536 100644 --- a/test/test_ssl.cpp +++ b/test/test_ssl.cpp @@ -196,7 +196,7 @@ void test_ssl(int test_idx, bool use_utp) ssl_peer_disconnects = 0; peer_errors = 0; - std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, nullptr , true, false, false, "_ssl", 16 * 1024, &t, false, &addp, true); if (test.seed_has_cert) diff --git a/test/test_storage.cpp b/test/test_storage.cpp index eaf6c2966..5d1e461ef 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -1022,7 +1022,7 @@ file_storage make_fs() struct test_fileop : fileop { - test_fileop(int stripe_size) : m_stripe_size(stripe_size) {} + explicit test_fileop(int stripe_size) : m_stripe_size(stripe_size) {} int file_op(int const file_index, std::int64_t const file_offset, int const size , file::iovec_t const* bufs, storage_error& ec) override @@ -1061,7 +1061,7 @@ struct test_fileop : fileop struct test_read_fileop : fileop { // EOF after size bytes read - test_read_fileop(int size) : m_size(size), m_counter(0) {} + explicit test_read_fileop(int size) : m_size(size), m_counter(0) {} int file_op(int const file_index, std::int64_t const file_offset, int const size , file::iovec_t const* bufs, storage_error& ec) override @@ -1091,7 +1091,7 @@ struct test_read_fileop : fileop struct test_error_fileop : fileop { // EOF after size bytes read - test_error_fileop(int error_file) + explicit test_error_fileop(int error_file) : m_error_file(error_file) {} int file_op(int const file_index, std::int64_t const file_offset, int const size diff --git a/test/test_tailqueue.cpp b/test/test_tailqueue.cpp index b838a1943..b55fd3290 100644 --- a/test/test_tailqueue.cpp +++ b/test/test_tailqueue.cpp @@ -37,7 +37,7 @@ using namespace libtorrent; struct test_node : tailqueue_node { - test_node(char n) : name(n) {} + explicit test_node(char n) : name(n) {} char name; }; diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index 284a49b9d..59b083dfb 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -312,7 +312,7 @@ struct test_plugin : libtorrent::torrent_plugin {}; struct plugin_creator { - plugin_creator(int& c) : m_called(c) {} + explicit plugin_creator(int& c) : m_called(c) {} boost::shared_ptr operator()(torrent_handle const&, void*) diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index 21e3cdd3b..4430b7538 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -71,7 +71,7 @@ bool on_alert(alert const* a) // simulate a full disk struct test_storage : default_storage { - test_storage(storage_params const& params) + explicit test_storage(storage_params const& params) : default_storage(params) , m_written(0) , m_limit(16 * 1024 * 2)