From 52cbfd4086a1a01cdfe9b380f62ea8139e2de444 Mon Sep 17 00:00:00 2001 From: Phoeniwx Date: Mon, 14 Nov 2022 20:49:06 +0800 Subject: [PATCH] Fix `modernize-avoid-bind` warning reported by clang-tidy (#1121) Co-authored-by: Twice Co-authored-by: wshi8 Co-authored-by: Twice --- .clang-tidy | 2 +- src/cluster/cluster.cc | 4 +++- src/commands/redis_cmd.cc | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 0ac1f3ff5da..4cdc81d1eba 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,7 +1,7 @@ # refer to https://clang.llvm.org/extra/clang-tidy/checks/list.html Checks: -*, clang-analyzer-core.*, clang-analyzer-cplusplus.*, clang-analyzer-deadcode.*, clang-analyzer-nullability.*, clang-analyzer-security.*, clang-analyzer-unix.*, clang-analyzer-valist.*, cppcoreguidelines-init-variables, cppcoreguidelines-macro-usage, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-no-malloc, cppcoreguidelines-prefer-member-initializer, cppcoreguidelines-special-member-functions, cppcoreguidelines-slicing, google-build-explicit-make-pair, google-default-arguments, google-explicit-constructor, modernize-avoid-bind, modernize-loop-convert, modernize-macro-to-enum, modernize-make-shared, modernize-make-unique, modernize-pass-by-value, modernize-redundant-void-arg, modernize-return-braced-init-list, modernize-use-auto, modernize-use-bool-literals, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, modernize-use-override, modernize-use-using, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-inefficient-vector-operation, performance-move-const-arg, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, performance-unnecessary-value-param -WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, cppcoreguidelines-slicing, google-*, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, modernize-use-bool-literals, performance-unnecessary-value-param, modernize-make-unique, performance-for-range-copy, performance-faster-string-find, modernize-redundant-void-arg +WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, cppcoreguidelines-slicing, google-*, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, modernize-use-bool-literals, performance-unnecessary-value-param, modernize-make-unique, performance-for-range-copy, performance-faster-string-find, modernize-redundant-void-arg, modernize-avoid-bind CheckOptions: - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor diff --git a/src/cluster/cluster.cc b/src/cluster/cluster.cc index da14d81c5d9..50b4561abf5 100644 --- a/src/cluster/cluster.cc +++ b/src/cluster/cluster.cc @@ -319,7 +319,9 @@ Status Cluster::ImportSlot(Redis::Connection *conn, int slot, int state) { conn->SetImporting(); myself_->importing_slot_ = slot; // Set link error callback - conn->close_cb_ = std::bind(&SlotImport::StopForLinkError, svr_->slot_import_, conn->GetFD()); + conn->close_cb_ = [object_ptr = svr_->slot_import_, capture_fd = conn->GetFD()](int fd) { + object_ptr->StopForLinkError(capture_fd); + }; // Stop forbidding writing slot to accept write commands if (slot == svr_->slot_migrate_->GetForbiddenSlot()) svr_->slot_migrate_->ReleaseForbiddenSlot(); LOG(INFO) << "[import] Start importing slot " << slot; diff --git a/src/commands/redis_cmd.cc b/src/commands/redis_cmd.cc index 3b477174e9e..652b790825a 100644 --- a/src/commands/redis_cmd.cc +++ b/src/commands/redis_cmd.cc @@ -3729,8 +3729,9 @@ class CommandUnSubscribe : public Commander { public: Status Execute(Server *svr, Connection *conn, std::string *output) override { if (args_.size() == 1) { - conn->UnSubscribeAll( - std::bind(SubscribeCommandReply, output, "unsubscribe", std::placeholders::_1, std::placeholders::_2)); + conn->UnSubscribeAll([output](const std::string &sub_name, int num) { + SubscribeCommandReply(output, "unsubscribe", sub_name, num); + }); } else { for (unsigned i = 1; i < args_.size(); i++) { conn->UnSubscribeChannel(args_[i]); @@ -3757,8 +3758,9 @@ class CommandPUnSubscribe : public Commander { public: Status Execute(Server *svr, Connection *conn, std::string *output) override { if (args_.size() == 1) { - conn->PUnSubscribeAll( - std::bind(SubscribeCommandReply, output, "punsubscribe", std::placeholders::_1, std::placeholders::_2)); + conn->PUnSubscribeAll([output](const std::string &sub_name, int num) { + SubscribeCommandReply(output, "punsubscribe", sub_name, num); + }); } else { for (unsigned i = 1; i < args_.size(); i++) { conn->PUnSubscribeChannel(args_[i]);