Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix modernize-use-auto warning reported by clang-tidy #1111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -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, modernize-avoid-bind
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, modernize-use-auto

CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
Expand Down
3 changes: 1 addition & 2 deletions src/commands/redis_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4713,8 +4713,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<std::chrono::microseconds>(end - start).count();
uint64_t shortest =
static_cast<uint64_t>(static_cast<double>(file_size) / max_replication_bytes * (1000 * 1000));
auto shortest = static_cast<uint64_t>(static_cast<double>(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";
Expand Down
8 changes: 4 additions & 4 deletions src/storage/batch_extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<RedisCommand>(*parse_result);
auto cmd = static_cast<RedisCommand>(*parse_result);
if (cmd == kRedisCmdExpire) {
command_args = {"EXPIREAT", user_key, std::to_string(metadata.expire)};
resp_commands_[ns].emplace_back(Redis::Command2RESP(command_args));
Expand Down Expand Up @@ -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<RedisCommand>(*parse_result);
auto cmd = static_cast<RedisCommand>(*parse_result);
switch (cmd) {
case kRedisCmdLSet:
if (args->size() < 2) {
Expand Down Expand Up @@ -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<RedisCommand>(*parse_result);
auto cmd = static_cast<RedisCommand>(*parse_result);
switch (cmd) {
case kRedisCmdSetBit: {
if (args->size() < 2) {
Expand Down Expand Up @@ -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<RedisCommand>(*parse_result);
auto cmd = static_cast<RedisCommand>(*parse_result);
switch (cmd) {
case kRedisCmdLTrim:
if (first_seen_) {
Expand Down
10 changes: 5 additions & 5 deletions src/types/redis_bitmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ rocksdb::Status Bitmap::BitCount(const Slice &user_key, int64_t start, int64_t s
if (stop > static_cast<int64_t>(metadata.size)) stop = metadata.size;
if (start < 0 || stop <= 0 || start >= stop) return rocksdb::Status::OK();

uint32_t u_start = static_cast<uint32_t>(start);
uint32_t u_stop = static_cast<uint32_t>(stop);
auto u_start = static_cast<uint32_t>(start);
auto u_stop = static_cast<uint32_t>(stop);

LatestSnapShot ss(db_);
rocksdb::ReadOptions read_options;
Expand Down Expand Up @@ -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<uint32_t>(start);
uint32_t u_stop = static_cast<uint32_t>(stop);
auto u_start = static_cast<uint32_t>(start);
auto u_stop = static_cast<uint32_t>(stop);

auto bitPosInByte = [](char byte, bool bit) -> int {
for (int i = 0; i < 8; i++) {
Expand Down Expand Up @@ -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<uint64_t *>(frag_res.get());
auto *lres = reinterpret_cast<uint64_t *>(frag_res.get());
const uint64_t *lp[16];
for (i = 0; i < frag_numkeys; i++) {
lp[i] = reinterpret_cast<const uint64_t *>(fragments[i].data());
Expand Down