From d25e6960574c00cd1955840ded135694b64739a5 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sun, 13 Nov 2022 02:44:51 +0300 Subject: [PATCH] Fix modernize-use-auto warning reported by clang-tidy --- .clang-tidy | 2 +- src/commands/redis_cmd.cc | 3 +-- src/storage/batch_extractor.cc | 8 ++++---- src/types/redis_bitmap.cc | 10 +++++----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 4f70482cacc..0548f6b10dd 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 +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-auto CheckOptions: - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor diff --git a/src/commands/redis_cmd.cc b/src/commands/redis_cmd.cc index 941ac4cc94f..b71b790b9e1 100644 --- a/src/commands/redis_cmd.cc +++ b/src/commands/redis_cmd.cc @@ -4711,8 +4711,7 @@ class CommandFetchFile : public Commander { // Sleep if the speed of sending file is more than replication speed limit auto end = std::chrono::high_resolution_clock::now(); uint64_t duration = std::chrono::duration_cast(end - start).count(); - uint64_t shortest = - static_cast(static_cast(file_size) / max_replication_bytes * (1000 * 1000)); + auto shortest = static_cast(static_cast(file_size) / max_replication_bytes * (1000 * 1000)); if (max_replication_bytes > 0 && duration < shortest) { LOG(INFO) << "[replication] Need to sleep " << (shortest - duration) / 1000 << " ms since of sending files too quickly"; diff --git a/src/storage/batch_extractor.cc b/src/storage/batch_extractor.cc index 833617eb26a..8d893db9c10 100644 --- a/src/storage/batch_extractor.cc +++ b/src/storage/batch_extractor.cc @@ -70,7 +70,7 @@ rocksdb::Status WriteBatchExtractor::PutCF(uint32_t column_family_id, const Slic if (!parse_result) { return rocksdb::Status::InvalidArgument(parse_result.Msg()); } - RedisCommand cmd = static_cast(*parse_result); + auto cmd = static_cast(*parse_result); if (cmd == kRedisCmdExpire) { command_args = {"EXPIREAT", user_key, std::to_string(metadata.expire)}; resp_commands_[ns].emplace_back(Redis::Command2RESP(command_args)); @@ -103,7 +103,7 @@ rocksdb::Status WriteBatchExtractor::PutCF(uint32_t column_family_id, const Slic if (!parse_result) { return rocksdb::Status::InvalidArgument(parse_result.Msg()); } - RedisCommand cmd = static_cast(*parse_result); + auto cmd = static_cast(*parse_result); switch (cmd) { case kRedisCmdLSet: if (args->size() < 2) { @@ -149,7 +149,7 @@ rocksdb::Status WriteBatchExtractor::PutCF(uint32_t column_family_id, const Slic if (!parse_result) { return rocksdb::Status::InvalidArgument(parse_result.Msg()); } - RedisCommand cmd = static_cast(*parse_result); + auto cmd = static_cast(*parse_result); switch (cmd) { case kRedisCmdSetBit: { if (args->size() < 2) { @@ -240,7 +240,7 @@ rocksdb::Status WriteBatchExtractor::DeleteCF(uint32_t column_family_id, const S if (!parse_result) { return rocksdb::Status::InvalidArgument(parse_result.Msg()); } - RedisCommand cmd = static_cast(*parse_result); + auto cmd = static_cast(*parse_result); switch (cmd) { case kRedisCmdLTrim: if (first_seen_) { diff --git a/src/types/redis_bitmap.cc b/src/types/redis_bitmap.cc index 9544a747777..8d800dd21d8 100644 --- a/src/types/redis_bitmap.cc +++ b/src/types/redis_bitmap.cc @@ -247,8 +247,8 @@ rocksdb::Status Bitmap::BitCount(const Slice &user_key, int64_t start, int64_t s if (stop > static_cast(metadata.size)) stop = metadata.size; if (start < 0 || stop <= 0 || start >= stop) return rocksdb::Status::OK(); - uint32_t u_start = static_cast(start); - uint32_t u_stop = static_cast(stop); + auto u_start = static_cast(start); + auto u_stop = static_cast(stop); LatestSnapShot ss(db_); rocksdb::ReadOptions read_options; @@ -297,8 +297,8 @@ rocksdb::Status Bitmap::BitPos(const Slice &user_key, bool bit, int64_t start, i *pos = -1; return rocksdb::Status::OK(); } - uint32_t u_start = static_cast(start); - uint32_t u_stop = static_cast(stop); + auto u_start = static_cast(start); + auto u_stop = static_cast(stop); auto bitPosInByte = [](char byte, bool bit) -> int { for (int i = 0; i < 8; i++) { @@ -430,7 +430,7 @@ rocksdb::Status Bitmap::BitOp(BitOpFlags op_flag, const std::string &op_name, co #ifndef USE_ALIGNED_ACCESS if (frag_minlen >= sizeof(uint64_t) * 4 && frag_numkeys <= 16) { - uint64_t *lres = reinterpret_cast(frag_res.get()); + auto *lres = reinterpret_cast(frag_res.get()); const uint64_t *lp[16]; for (i = 0; i < frag_numkeys; i++) { lp[i] = reinterpret_cast(fragments[i].data());