From 3428076ecd16d8fe273b8d835ef1b3907db051ea Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 3 Aug 2022 12:03:28 -0500 Subject: [PATCH] fix: cppcoreguidelines-special-member-functions warnings in libtransmission (#3575) --- libtransmission/.clang-tidy | 1 + libtransmission/announcer.cc | 5 +++++ libtransmission/crypto-utils-openssl.cc | 10 ++++++++++ libtransmission/handshake.cc | 5 +++++ libtransmission/peer-mgr.cc | 15 +++++++++++++++ libtransmission/peer-msgs.cc | 5 +++++ libtransmission/session.cc | 3 +-- libtransmission/upnp.cc | 6 ++++++ libtransmission/variant-benc.cc | 5 +++++ libtransmission/watchdir.cc | 10 +++++++--- libtransmission/web.cc | 5 +++++ libtransmission/webseed.cc | 5 +++++ 12 files changed, 70 insertions(+), 5 deletions(-) diff --git a/libtransmission/.clang-tidy b/libtransmission/.clang-tidy index d8c3270d9..681531d4f 100644 --- a/libtransmission/.clang-tidy +++ b/libtransmission/.clang-tidy @@ -18,6 +18,7 @@ Checks: > cppcoreguidelines-init-variables, cppcoreguidelines-prefer-member-initializer, cppcoreguidelines-slicing, + cppcoreguidelines-special-member-functions, cppcoreguidelines-virtual-class-destructor, misc-*, -misc-no-recursion, diff --git a/libtransmission/announcer.cc b/libtransmission/announcer.cc index 0a64e236a..4d31dce31 100644 --- a/libtransmission/announcer.cc +++ b/libtransmission/announcer.cc @@ -169,6 +169,11 @@ struct tr_announcer scheduleNextUpdate(); } + tr_announcer(tr_announcer&&) = delete; + tr_announcer(tr_announcer const&) = delete; + tr_announcer& operator=(tr_announcer&&) = delete; + tr_announcer& operator=(tr_announcer const&) = delete; + ~tr_announcer() { event_free(upkeep_timer); diff --git a/libtransmission/crypto-utils-openssl.cc b/libtransmission/crypto-utils-openssl.cc index 3c2ed28fd..43d231eff 100644 --- a/libtransmission/crypto-utils-openssl.cc +++ b/libtransmission/crypto-utils-openssl.cc @@ -146,7 +146,12 @@ private: class Sha1Impl final : public tr_sha1 { public: + Sha1Impl() = default; + Sha1Impl(Sha1Impl&&) = delete; + Sha1Impl(Sha1Impl const&) = delete; ~Sha1Impl() override = default; + Sha1Impl& operator=(Sha1Impl&&) = delete; + Sha1Impl& operator=(Sha1Impl const&) = delete; void clear() override { @@ -170,7 +175,12 @@ private: class Sha256Impl final : public tr_sha256 { public: + Sha256Impl() = default; + Sha256Impl(Sha256Impl&&) = delete; + Sha256Impl(Sha256Impl const&) = delete; ~Sha256Impl() override = default; + Sha256Impl& operator=(Sha256Impl&&) = delete; + Sha256Impl& operator=(Sha256Impl const&) = delete; void clear() override { diff --git a/libtransmission/handshake.cc b/libtransmission/handshake.cc index b338637e7..7a4bc8e08 100644 --- a/libtransmission/handshake.cc +++ b/libtransmission/handshake.cc @@ -119,6 +119,11 @@ struct tr_handshake { } + tr_handshake(tr_handshake&&) = delete; + tr_handshake(tr_handshake const&) = delete; + tr_handshake& operator=(tr_handshake&&) = delete; + tr_handshake& operator=(tr_handshake const&) = delete; + ~tr_handshake() { if (io != nullptr) diff --git a/libtransmission/peer-mgr.cc b/libtransmission/peer-mgr.cc index 6cc92095b..7e3afc5ea 100644 --- a/libtransmission/peer-mgr.cc +++ b/libtransmission/peer-mgr.cc @@ -88,6 +88,11 @@ public: { } + tr_handshake_mediator_impl(tr_handshake_mediator_impl&&) = delete; + tr_handshake_mediator_impl(tr_handshake_mediator_impl const&) = delete; + tr_handshake_mediator_impl& operator=(tr_handshake_mediator_impl&&) = delete; + tr_handshake_mediator_impl& operator=(tr_handshake_mediator_impl const&) = delete; + virtual ~tr_handshake_mediator_impl() = default; [[nodiscard]] std::optional torrentInfo(tr_sha1_digest_t const& info_hash) const override @@ -578,6 +583,11 @@ struct tr_peerMgr tr_timerAddMsec(*refill_upkeep_timer_, RefillUpkeepPeriodMsec); } + tr_peerMgr(tr_peerMgr&&) = delete; + tr_peerMgr(tr_peerMgr const&) = delete; + tr_peerMgr& operator=(tr_peerMgr&&) = delete; + tr_peerMgr& operator=(tr_peerMgr const&) = delete; + [[nodiscard]] auto unique_lock() const { return session->unique_lock(); @@ -824,6 +834,11 @@ std::vector tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_p { } + MediatorImpl(MediatorImpl&&) = delete; + MediatorImpl(MediatorImpl const&) = delete; + MediatorImpl& operator=(MediatorImpl&&) = delete; + MediatorImpl& operator=(MediatorImpl const&) = delete; + ~MediatorImpl() override = default; [[nodiscard]] bool clientCanRequestBlock(tr_block_index_t block) const override diff --git a/libtransmission/peer-msgs.cc b/libtransmission/peer-msgs.cc index b19d9dca4..4e67f9f3a 100644 --- a/libtransmission/peer-msgs.cc +++ b/libtransmission/peer-msgs.cc @@ -300,6 +300,11 @@ public: updateDesiredRequestCount(this); } + tr_peerMsgsImpl(tr_peerMsgsImpl&&) = delete; + tr_peerMsgsImpl(tr_peerMsgsImpl const&) = delete; + tr_peerMsgsImpl& operator=(tr_peerMsgsImpl&&) = delete; + tr_peerMsgsImpl& operator=(tr_peerMsgsImpl const&) = delete; + ~tr_peerMsgsImpl() override { set_active(TR_UP, false); diff --git a/libtransmission/session.cc b/libtransmission/session.cc index 0b6fc3ef2..735ed2c22 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -1296,9 +1296,8 @@ uint16_t tr_sessionGetPeerPort(tr_session const* session) uint16_t tr_sessionSetPeerPortRandom(tr_session* session) { - tr_port p = getRandomPort(session); + tr_port const p = getRandomPort(session); tr_sessionSetPeerPort(session, p.host()); - return p.host(); } diff --git a/libtransmission/upnp.cc b/libtransmission/upnp.cc index fee8596fd..f84080f75 100644 --- a/libtransmission/upnp.cc +++ b/libtransmission/upnp.cc @@ -66,6 +66,12 @@ tr_port_forwarding portFwdState(UpnpState upnp_state, bool is_mapped) struct tr_upnp { + tr_upnp() = default; + tr_upnp(tr_upnp&&) = delete; + tr_upnp(tr_upnp const&) = delete; + tr_upnp& operator=(tr_upnp&&) = delete; + tr_upnp& operator=(tr_upnp const&) = delete; + ~tr_upnp() { TR_ASSERT(!isMapped); diff --git a/libtransmission/variant-benc.cc b/libtransmission/variant-benc.cc index fc7e1ee0b..88a1f822d 100644 --- a/libtransmission/variant-benc.cc +++ b/libtransmission/variant-benc.cc @@ -144,6 +144,11 @@ struct MyHandler : public transmission::benc::Handler { } + MyHandler(MyHandler&&) = delete; + MyHandler(MyHandler const&) = delete; + MyHandler& operator=(MyHandler&&) = delete; + MyHandler& operator=(MyHandler const&) = delete; + ~MyHandler() override = default; bool Int64(int64_t value, Context const& /*context*/) final diff --git a/libtransmission/watchdir.cc b/libtransmission/watchdir.cc index 9c1c90d9e..246d465b4 100644 --- a/libtransmission/watchdir.cc +++ b/libtransmission/watchdir.cc @@ -43,7 +43,9 @@ auto tr_watchdir_retry_max_interval = timeval{ 10, 0 }; class tr_watchdir_retry { public: + tr_watchdir_retry(tr_watchdir_retry&&) = delete; tr_watchdir_retry(tr_watchdir_retry const&) = delete; + tr_watchdir_retry& operator=(tr_watchdir_retry&&) = delete; tr_watchdir_retry& operator=(tr_watchdir_retry const&) = delete; tr_watchdir_retry(tr_watchdir_t handle_in, struct event_base* base, std::string_view name_in) @@ -139,6 +141,11 @@ public: } } + tr_watchdir(tr_watchdir&&) = delete; + tr_watchdir(tr_watchdir const&) = delete; + tr_watchdir& operator=(tr_watchdir&&) = delete; + tr_watchdir& operator=(tr_watchdir const&) = delete; + ~tr_watchdir() { if (backend_ != nullptr) @@ -147,9 +154,6 @@ public: } } - tr_watchdir(tr_watchdir const&) = delete; - tr_watchdir& operator=(tr_watchdir const&) = delete; - [[nodiscard]] constexpr auto const& path() const noexcept { return path_; diff --git a/libtransmission/web.cc b/libtransmission/web.cc index c9d51a4ba..31c3e4144 100644 --- a/libtransmission/web.cc +++ b/libtransmission/web.cc @@ -139,6 +139,11 @@ public: curl_thread = std::make_unique(curlThreadFunc, this); } + Impl(Impl&&) = delete; + Impl(Impl const&) = delete; + Impl& operator=(Impl&&) = delete; + Impl& operator=(Impl const&) = delete; + ~Impl() { run_mode = RunMode::CloseNow; diff --git a/libtransmission/webseed.cc b/libtransmission/webseed.cc index 4d8951beb..8b50fe679 100644 --- a/libtransmission/webseed.cc +++ b/libtransmission/webseed.cc @@ -169,6 +169,11 @@ public: startTimer(); } + tr_webseed(tr_webseed&&) = delete; + tr_webseed(tr_webseed const&) = delete; + tr_webseed& operator=(tr_webseed&&) = delete; + tr_webseed& operator=(tr_webseed const&) = delete; + ~tr_webseed() override { // flag all the pending tasks as dead