Skip to content

Commit d373187

Browse files
authored
chore: fix some clang-tidy warnings (#5009)
1 parent 59a347d commit d373187

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

.clang-tidy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Checks: >
1212
performance*,
1313
cert*,
1414
-cert-err58-cpp,
15+
-cert-dcl58-cpp, # Ignore std changes
1516
# Doesn't work with abseil flags
1617
clang-analyzer*,
1718
google-*,
@@ -81,4 +82,9 @@ Checks: >
8182
# modernize-use-nullptr,
8283
# modernize-use-equals-default,
8384
# readability-qualified-auto,
84-
cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion: 'false'
85+
86+
CheckOptions:
87+
- key: bugprone-narrowing-conversions.WarnOnIntegerNarrowingConversion
88+
value: false
89+
- key: bugprone-narrowing-conversions.WarnOnEquivalentBitWidth
90+
value: false

src/facade/facade_types.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ struct ArgRange {
6363
ArgRange(ArgRange& range) : ArgRange((const ArgRange&)range) {
6464
}
6565

66-
template <typename T> ArgRange(T&& span) : span(std::forward<T>(span)) {
66+
template <typename T, std::enable_if_t<!std::is_same_v<ArgRange, T>, bool> = true>
67+
ArgRange(T&& span) : span(std::forward<T>(span)) { // NOLINT google-explicit-constructor)
6768
}
6869

6970
size_t Size() const {
@@ -163,7 +164,9 @@ struct ErrorReply {
163164
std::string_view kind = {}) // to resolve ambiguity of constructors above
164165
: message{std::string_view{msg}}, kind{kind} {
165166
}
166-
ErrorReply(OpStatus status) : message{}, kind{}, status{status} {
167+
168+
ErrorReply(OpStatus status) // NOLINT google-explicit-constructor)
169+
: status{status} {
167170
}
168171

169172
std::string_view ToSv() const {

src/server/list_family.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ OpResult<string> Peek(const OpArgs& op_args, string_view key, ListDir dir, bool
324324
}
325325

326326
OpResult<uint32_t> OpPush(const OpArgs& op_args, std::string_view key, ListDir dir,
327-
bool skip_notexist, facade::ArgRange vals, bool journal_rewrite) {
327+
bool skip_notexist, const facade::ArgRange& vals, bool journal_rewrite) {
328328
EngineShard* es = op_args.shard;
329329
DbSlice::ItAndUpdater res;
330330

@@ -666,7 +666,7 @@ OpResult<int> OpInsert(const OpArgs& op_args, string_view key, string_view pivot
666666
QList* ql = GetQLV2(pv);
667667
QList::InsertOpt insert_opt = (insert_param == INSERT_BEFORE) ? QList::BEFORE : QList::AFTER;
668668
if (ql->Insert(pivot, elem, insert_opt)) {
669-
res = ql->Size();
669+
res = int(ql->Size());
670670
}
671671
} else {
672672
quicklist* ql = GetQL(pv);
@@ -688,7 +688,7 @@ OpResult<int> OpInsert(const OpArgs& op_args, string_view key, string_view pivot
688688
DCHECK_EQ(INSERT_BEFORE, insert_param);
689689
quicklistInsertBefore(qiter, &entry, elem.data(), elem.size());
690690
}
691-
res = quicklistCount(ql);
691+
res = int(quicklistCount(ql));
692692
}
693693
quicklistReleaseIterator(qiter);
694694
}
@@ -809,7 +809,7 @@ OpStatus OpTrim(const OpArgs& op_args, string_view key, long start, long end) {
809809

810810
auto it = it_res->it;
811811

812-
long llen = it->second.Size();
812+
long llen = long(it->second.Size());
813813

814814
/* convert negative indexes */
815815
if (start < 0)
@@ -1324,27 +1324,27 @@ void ListFamily::LMPop(CmdArgList args, const CommandContext& cmd_cntx) {
13241324
}
13251325

13261326
void ListFamily::LPush(CmdArgList args, const CommandContext& cmd_cntx) {
1327-
return PushGeneric(ListDir::LEFT, false, std::move(args), cmd_cntx.tx, cmd_cntx.rb);
1327+
return PushGeneric(ListDir::LEFT, false, args, cmd_cntx.tx, cmd_cntx.rb);
13281328
}
13291329

13301330
void ListFamily::LPushX(CmdArgList args, const CommandContext& cmd_cntx) {
1331-
return PushGeneric(ListDir::LEFT, true, std::move(args), cmd_cntx.tx, cmd_cntx.rb);
1331+
return PushGeneric(ListDir::LEFT, true, args, cmd_cntx.tx, cmd_cntx.rb);
13321332
}
13331333

13341334
void ListFamily::LPop(CmdArgList args, const CommandContext& cmd_cntx) {
1335-
return PopGeneric(ListDir::LEFT, std::move(args), cmd_cntx.tx, cmd_cntx.rb);
1335+
return PopGeneric(ListDir::LEFT, args, cmd_cntx.tx, cmd_cntx.rb);
13361336
}
13371337

13381338
void ListFamily::RPush(CmdArgList args, const CommandContext& cmd_cntx) {
1339-
return PushGeneric(ListDir::RIGHT, false, std::move(args), cmd_cntx.tx, cmd_cntx.rb);
1339+
return PushGeneric(ListDir::RIGHT, false, args, cmd_cntx.tx, cmd_cntx.rb);
13401340
}
13411341

13421342
void ListFamily::RPushX(CmdArgList args, const CommandContext& cmd_cntx) {
1343-
return PushGeneric(ListDir::RIGHT, true, std::move(args), cmd_cntx.tx, cmd_cntx.rb);
1343+
return PushGeneric(ListDir::RIGHT, true, args, cmd_cntx.tx, cmd_cntx.rb);
13441344
}
13451345

13461346
void ListFamily::RPop(CmdArgList args, const CommandContext& cmd_cntx) {
1347-
return PopGeneric(ListDir::RIGHT, std::move(args), cmd_cntx.tx, cmd_cntx.rb);
1347+
return PopGeneric(ListDir::RIGHT, args, cmd_cntx.tx, cmd_cntx.rb);
13481348
}
13491349

13501350
void ListFamily::LLen(CmdArgList args, const CommandContext& cmd_cntx) {
@@ -1563,11 +1563,11 @@ void ListFamily::LSet(CmdArgList args, const CommandContext& cmd_cntx) {
15631563
}
15641564

15651565
void ListFamily::BLPop(CmdArgList args, const CommandContext& cmd_cntx) {
1566-
BPopGeneric(ListDir::LEFT, std::move(args), cmd_cntx.tx, cmd_cntx.rb, cmd_cntx.conn_cntx);
1566+
BPopGeneric(ListDir::LEFT, args, cmd_cntx.tx, cmd_cntx.rb, cmd_cntx.conn_cntx);
15671567
}
15681568

15691569
void ListFamily::BRPop(CmdArgList args, const CommandContext& cmd_cntx) {
1570-
BPopGeneric(ListDir::RIGHT, std::move(args), cmd_cntx.tx, cmd_cntx.rb, cmd_cntx.conn_cntx);
1570+
BPopGeneric(ListDir::RIGHT, args, cmd_cntx.tx, cmd_cntx.rb, cmd_cntx.conn_cntx);
15711571
}
15721572

15731573
void ListFamily::LMove(CmdArgList args, const CommandContext& cmd_cntx) {

src/server/main_service.cc

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ void DispatchMonitor(ConnectionContext* cntx, const CommandId* cid, CmdArgList t
287287

288288
class InterpreterReplier : public RedisReplyBuilder {
289289
public:
290-
InterpreterReplier(ObjectExplorer* explr) : RedisReplyBuilder(nullptr), explr_(explr) {
290+
explicit InterpreterReplier(ObjectExplorer* explr) : RedisReplyBuilder(nullptr), explr_(explr) {
291291
}
292292

293-
void SendError(std::string_view str, std::string_view type = std::string_view{}) final;
293+
void SendError(std::string_view str, std::string_view type) final;
294294

295295
void SendBulkString(std::string_view str) final;
296296
void SendSimpleString(std::string_view str) final;
@@ -313,7 +313,7 @@ class InterpreterReplier : public RedisReplyBuilder {
313313
// Serialized result of script invocation to Redis protocol
314314
class EvalSerializer : public ObjectExplorer {
315315
public:
316-
EvalSerializer(RedisReplyBuilder* rb) : rb_(rb) {
316+
explicit EvalSerializer(RedisReplyBuilder* rb) : rb_(rb) {
317317
}
318318

319319
void OnBool(bool b) final {
@@ -443,11 +443,8 @@ void InterpreterReplier::StartCollection(unsigned len, CollectionType type) {
443443
}
444444

445445
bool IsSHA(string_view str) {
446-
for (auto c : str) {
447-
if (!absl::ascii_isxdigit(c))
448-
return false;
449-
}
450-
return true;
446+
return std::all_of(str.begin(), str.end(),
447+
[](unsigned char c) { return absl::ascii_isxdigit(c); });
451448
}
452449

453450
optional<ErrorReply> EvalValidator(CmdArgList args) {
@@ -2102,12 +2099,8 @@ bool CheckWatchedKeyExpiry(ConnectionContext* cntx, const CommandId* exists_cid,
21022099

21032100
// Check if exec_info watches keys on dbs other than db_indx.
21042101
bool IsWatchingOtherDbs(DbIndex db_indx, const ConnectionState::ExecInfo& exec_info) {
2105-
for (const auto& [key_db, _] : exec_info.watched_keys) {
2106-
if (key_db != db_indx) {
2107-
return true;
2108-
}
2109-
}
2110-
return false;
2102+
return std::any_of(exec_info.watched_keys.begin(), exec_info.watched_keys.end(),
2103+
[db_indx](const auto& pair) { return pair.first != db_indx; });
21112104
}
21122105

21132106
template <typename F> void IterateAllKeys(ConnectionState::ExecInfo* exec_info, F&& f) {
@@ -2275,7 +2268,7 @@ void SubscribeImpl(bool reject_cluster, CmdArgList args, const CommandContext& c
22752268
if (reject_cluster && IsClusterEnabled()) {
22762269
return cmd_cntx.rb->SendError("SUBSCRIBE is not supported in cluster mode yet");
22772270
}
2278-
cmd_cntx.conn_cntx->ChangeSubscription(true /*add*/, true /* reply*/, std::move(args),
2271+
cmd_cntx.conn_cntx->ChangeSubscription(true /*add*/, true /* reply*/, args,
22792272
static_cast<RedisReplyBuilder*>(cmd_cntx.rb));
22802273
}
22812274

0 commit comments

Comments
 (0)