From ae71d5b467e1e568b83a2e78d630d1c09637df61 Mon Sep 17 00:00:00 2001 From: wshi8 Date: Mon, 14 Nov 2022 17:44:30 +0800 Subject: [PATCH 1/4] fix: #1094 modernize-avoid-bind warning --- src/cluster/cluster.cc | 3 ++- src/commands/redis_cmd.cc | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cluster/cluster.cc b/src/cluster/cluster.cc index da14d81c5d9..435803fffcb 100644 --- a/src/cluster/cluster.cc +++ b/src/cluster/cluster.cc @@ -319,7 +319,8 @@ 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_ = std::bind(&SlotImport::StopForLinkError, svr_->slot_import_, conn->GetFD()); + conn->close_cb_ = [ObjectPtr = svr_->slot_import_, captureFd = conn->GetFD()](int fd) {ObjectPtr->StopForLinkError(captureFd);}; // 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..bcbe2351bb9 100644 --- a/src/commands/redis_cmd.cc +++ b/src/commands/redis_cmd.cc @@ -3730,7 +3730,10 @@ class CommandUnSubscribe : public Commander { 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)); + [output](const std::string &sub_name, int num){SubscribeCommandReply(output, "unsubscribe", sub_name, num);} + ); + // conn->UnSubscribeAll( + // std::bind(SubscribeCommandReply, output, "unsubscribe", std::placeholders::_1, std::placeholders::_2)); } else { for (unsigned i = 1; i < args_.size(); i++) { conn->UnSubscribeChannel(args_[i]); @@ -3758,7 +3761,10 @@ class CommandPUnSubscribe : public Commander { 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)); + [output](const std::string &sub_name, int num) {SubscribeCommandReply(output, "punsubscribe", sub_name, num);} + ); + // conn->PUnSubscribeAll( + // std::bind(SubscribeCommandReply, output, "punsubscribe", std::placeholders::_1, std::placeholders::_2)); } else { for (unsigned i = 1; i < args_.size(); i++) { conn->PUnSubscribeChannel(args_[i]); From 9c18c3dab04aaa771d78796cb64e4fb8e35601bd Mon Sep 17 00:00:00 2001 From: wshi8 Date: Mon, 14 Nov 2022 18:29:01 +0800 Subject: [PATCH 2/4] Rename vars and & remove comments & format code --- src/cluster/cluster.cc | 5 +++-- src/commands/redis_cmd.cc | 16 ++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/cluster/cluster.cc b/src/cluster/cluster.cc index 435803fffcb..50b4561abf5 100644 --- a/src/cluster/cluster.cc +++ b/src/cluster/cluster.cc @@ -319,8 +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_ = [ObjectPtr = svr_->slot_import_, captureFd = conn->GetFD()](int fd) {ObjectPtr->StopForLinkError(captureFd);}; + 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 bcbe2351bb9..652b790825a 100644 --- a/src/commands/redis_cmd.cc +++ b/src/commands/redis_cmd.cc @@ -3729,11 +3729,9 @@ class CommandUnSubscribe : public Commander { public: Status Execute(Server *svr, Connection *conn, std::string *output) override { if (args_.size() == 1) { - conn->UnSubscribeAll( - [output](const std::string &sub_name, int num){SubscribeCommandReply(output, "unsubscribe", sub_name, num);} - ); - // 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]); @@ -3760,11 +3758,9 @@ class CommandPUnSubscribe : public Commander { public: Status Execute(Server *svr, Connection *conn, std::string *output) override { if (args_.size() == 1) { - conn->PUnSubscribeAll( - [output](const std::string &sub_name, int num) {SubscribeCommandReply(output, "punsubscribe", sub_name, num);} - ); - // 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]); From 1e5df616f6c58cdbee1c9a8e8c1e5246598d0715 Mon Sep 17 00:00:00 2001 From: wshi8 Date: Mon, 14 Nov 2022 18:29:34 +0800 Subject: [PATCH 3/4] update .clang-tidy +modernize-avoid-bind --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index c8274ac0e30..39fc41f5b7e 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 +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, modernize-avoid-bind CheckOptions: - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor From e22cc4dccbb6edba6e122e08af6dd128600459cb Mon Sep 17 00:00:00 2001 From: Phoeniwx Date: Mon, 14 Nov 2022 19:16:02 +0800 Subject: [PATCH 4/4] Update .clang-tidy Co-authored-by: Twice --- .clang-tidy | 1 - 1 file changed, 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index b68fc1041a1..4cdc81d1eba 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,7 +1,6 @@ # 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, modernize-avoid-bind CheckOptions: