Skip to content

Commit

Permalink
chore: Enable -Werror=unused-parameter flag (apache#2507)
Browse files Browse the repository at this point in the history
  • Loading branch information
c8ef authored Aug 27, 2024
1 parent 39aeefe commit fa3290c
Show file tree
Hide file tree
Showing 40 changed files with 174 additions and 153 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ add_library(kvrocks_objs OBJECT ${KVROCKS_SRCS})
target_include_directories(kvrocks_objs PUBLIC src src/common src/vendor ${PROJECT_BINARY_DIR} ${Backtrace_INCLUDE_DIR})
target_compile_features(kvrocks_objs PUBLIC cxx_std_17)
target_compile_options(kvrocks_objs PUBLIC -Wall -Wpedantic -Wsign-compare -Wreturn-type -fno-omit-frame-pointer)
target_compile_options(kvrocks_objs PUBLIC -Werror=unused-parameter)
target_compile_options(kvrocks_objs PUBLIC -Werror=unused-result)

# disable unused-variable check on GCC < 8 due to the structure bindings
Expand Down
2 changes: 1 addition & 1 deletion src/cli/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

Server *srv = nullptr;

extern "C" void SignalHandler(int sig) {
extern "C" void SignalHandler([[maybe_unused]] int sig) {
if (srv && !srv->IsStopped()) {
LOG(INFO) << "Bye Bye";
srv->Stop();
Expand Down
2 changes: 1 addition & 1 deletion src/cli/signal_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "version_util.h"

extern "C" inline void SegvHandler(int sig, siginfo_t *info, void *secret) {
extern "C" inline void SegvHandler(int sig, [[maybe_unused]] siginfo_t *info, [[maybe_unused]] void *secret) {
LOG(ERROR) << "Ooops! Apache Kvrocks " << PrintVersion << " got signal: " << strsignal(sig) << " (" << sig << ")";
auto trace = cpptrace::generate_trace();
trace.print(LOG(ERROR));
Expand Down
2 changes: 1 addition & 1 deletion src/cluster/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ Status Cluster::ImportSlotRange(redis::Connection *conn, const SlotRange &slot_r
conn->SetImporting();
myself_->importing_slot_range = slot_range;
// Set link error callback
conn->close_cb = [object_ptr = srv_->slot_import.get(), slot_range](int fd) {
conn->close_cb = [object_ptr = srv_->slot_import.get(), slot_range]([[maybe_unused]] int fd) {
auto s = object_ptr->StopForLinkError();
if (!s.IsOK()) {
LOG(ERROR) << fmt::format("[import] Failed to stop importing slot(s) {}: {}", slot_range.String(), s.Msg());
Expand Down
8 changes: 5 additions & 3 deletions src/cluster/replication.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,13 @@ class ReplicationThread : private EventCallbackBase<ReplicationThread> {
class WriteBatchHandler : public rocksdb::WriteBatch::Handler {
public:
rocksdb::Status PutCF(uint32_t column_family_id, const rocksdb::Slice &key, const rocksdb::Slice &value) override;
rocksdb::Status DeleteCF(uint32_t column_family_id, const rocksdb::Slice &key) override {
rocksdb::Status DeleteCF([[maybe_unused]] uint32_t column_family_id,
[[maybe_unused]] const rocksdb::Slice &key) override {
return rocksdb::Status::OK();
}
rocksdb::Status DeleteRangeCF(uint32_t column_family_id, const rocksdb::Slice &begin_key,
const rocksdb::Slice &end_key) override {
rocksdb::Status DeleteRangeCF([[maybe_unused]] uint32_t column_family_id,
[[maybe_unused]] const rocksdb::Slice &begin_key,
[[maybe_unused]] const rocksdb::Slice &end_key) override {
return rocksdb::Status::OK();
}
WriteBatchType Type() { return type_; }
Expand Down
2 changes: 1 addition & 1 deletion src/cluster/sync_migrate_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void SyncMigrateContext::OnEvent(bufferevent *bev, int16_t events) {
conn_->OnEvent(bev, events);
}

void SyncMigrateContext::TimerCB(int, int16_t events) {
void SyncMigrateContext::TimerCB(int, [[maybe_unused]] int16_t events) {
auto &&slot_migrator = srv_->slot_migrator;

conn_->Reply(conn_->NilString());
Expand Down
6 changes: 3 additions & 3 deletions src/commands/cmd_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ static uint64_t GenerateClusterFlag(uint64_t flags, const std::vector<std::strin

class CommandReadOnly : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
*output = redis::SimpleString("OK");
conn->EnableFlag(redis::Connection::kReadOnly);
return Status::OK();
Expand All @@ -338,7 +338,7 @@ class CommandReadOnly : public Commander {

class CommandReadWrite : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
*output = redis::SimpleString("OK");
conn->DisableFlag(redis::Connection::kReadOnly);
return Status::OK();
Expand All @@ -347,7 +347,7 @@ class CommandReadWrite : public Commander {

class CommandAsking : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
conn->EnableFlag(redis::Connection::kAsking);
*output = redis::SimpleString("OK");
return Status::OK();
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct CommandFunction : Commander {

template <bool read_only = false>
struct CommandFCall : Commander {
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
int64_t numkeys = GET_OR_RET(ParseInt<int64_t>(args_[2], 10));
if (numkeys > int64_t(args_.size() - 3)) {
return {Status::NotOK, "Number of keys can't be greater than number of args"};
Expand Down
4 changes: 3 additions & 1 deletion src/commands/cmd_geo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,9 @@ class CommandGeoSearchStore : public CommandGeoSearch {
return Status::OK();
}

static std::vector<CommandKeyRange> Range(const std::vector<std::string> &args) { return {{1, 1, 1}, {2, 2, 1}}; }
static std::vector<CommandKeyRange> Range([[maybe_unused]] const std::vector<std::string> &args) {
return {{1, 1, 1}, {2, 2, 1}};
}

private:
bool store_distance_ = false;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/cmd_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class CommandJsonMerge : public Commander {

class CommandJsonArrPop : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
Status Parse([[maybe_unused]] const std::vector<std::string> &args) override {
path_ = (args_.size() > 2) ? args_[2] : "$";

if (args_.size() == 4) {
Expand Down Expand Up @@ -417,7 +417,7 @@ class CommandJsonObjLen : public Commander {

class CommandJsonArrTrim : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
Status Parse([[maybe_unused]] const std::vector<std::string> &args) override {
path_ = args_[2];
start_ = GET_OR_RET(ParseInt<int64_t>(args_[3], 10));
stop_ = GET_OR_RET(ParseInt<int64_t>(args_[4], 10));
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ class CommandRPopLPUSH : public Commander {

class CommandLMove : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
Status Parse([[maybe_unused]] const std::vector<std::string> &args) override {
auto arg_val = util::ToLower(args_[3]);
if (arg_val != "left" && arg_val != "right") {
return {Status::RedisParseErr, errInvalidSyntax};
Expand Down
12 changes: 6 additions & 6 deletions src/commands/cmd_pubsub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace redis {

class CommandPublish : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
if (!srv->IsSlave()) {
// Compromise: can't replicate a message to sub-replicas in a cascading-like structure.
// Replication relies on WAL seq; increasing the seq on a replica will break the replication process,
Expand All @@ -50,7 +50,7 @@ class CommandPublish : public Commander {

class CommandMPublish : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
int total_receivers = 0;
engine::Context ctx(srv->storage);
for (size_t i = 2; i < args_.size(); i++) {
Expand Down Expand Up @@ -83,7 +83,7 @@ void SubscribeCommandReply(const Connection *conn, std::string *output, const st

class CommandSubscribe : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
for (unsigned i = 1; i < args_.size(); i++) {
conn->SubscribeChannel(args_[i]);
SubscribeCommandReply(conn, output, "subscribe", args_[i],
Expand All @@ -95,7 +95,7 @@ class CommandSubscribe : public Commander {

class CommandUnSubscribe : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
if (args_.size() == 1) {
conn->UnsubscribeAll([conn, output](const std::string &sub_name, int num) {
SubscribeCommandReply(conn, output, "unsubscribe", sub_name, num);
Expand All @@ -113,7 +113,7 @@ class CommandUnSubscribe : public Commander {

class CommandPSubscribe : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
for (size_t i = 1; i < args_.size(); i++) {
conn->PSubscribeChannel(args_[i]);
SubscribeCommandReply(conn, output, "psubscribe", args_[i],
Expand All @@ -125,7 +125,7 @@ class CommandPSubscribe : public Commander {

class CommandPUnSubscribe : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
if (args_.size() == 1) {
conn->PUnsubscribeAll([conn, output](const std::string &sub_name, int num) {
SubscribeCommandReply(conn, output, "punsubscribe", sub_name, num);
Expand Down
12 changes: 6 additions & 6 deletions src/commands/cmd_replication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class CommandReplConf : public Commander {
return Status::OK();
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
if (port_ != 0) {
conn->SetListeningPort(port_);
}
Expand All @@ -204,9 +204,9 @@ class CommandReplConf : public Commander {

class CommandFetchMeta : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override { return Status::OK(); }
Status Parse([[maybe_unused]] const std::vector<std::string> &args) override { return Status::OK(); }

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, Connection *conn, [[maybe_unused]] std::string *output) override {
int repl_fd = conn->GetFD();
std::string ip = conn->GetAnnounceIP();

Expand Down Expand Up @@ -262,7 +262,7 @@ class CommandFetchFile : public Commander {
return Status::OK();
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, Connection *conn, [[maybe_unused]] std::string *output) override {
std::vector<std::string> files = util::Split(files_str_, ",");

int repl_fd = conn->GetFD();
Expand Down Expand Up @@ -332,9 +332,9 @@ class CommandFetchFile : public Commander {

class CommandDBName : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override { return Status::OK(); }
Status Parse([[maybe_unused]] const std::vector<std::string> &args) override { return Status::OK(); }

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, Connection *conn, [[maybe_unused]] std::string *output) override {
conn->Reply(srv->storage->GetName() + CRLF);
return Status::OK();
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/cmd_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace redis {
template <bool evalsha, bool read_only>
class CommandEvalImpl : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
if (evalsha && args_[1].size() != 40) {
return {Status::RedisNoScript, errNoMatchingScript};
}
Expand Down Expand Up @@ -62,7 +62,7 @@ class CommandScript : public Commander {
return Status::OK();
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
// There's a little tricky here since the script command was the write type
// command but some subcommands like `exists` were readonly, so we want to allow
// executing on slave here. Maybe we should find other way to do this.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static StatusOr<CommandParserWithNode> ParseSQLQuery(const std::vector<std::stri
}

class CommandFTExplainSQL : public Commander {
Status Parse(const std::vector<std::string> &args) override {
Status Parse([[maybe_unused]] const std::vector<std::string> &args) override {
auto [parser, ir] = GET_OR_RET(ParseSQLQuery(args_));
ir_ = std::move(ir);

Expand Down
30 changes: 15 additions & 15 deletions src/commands/cmd_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class CommandFlushAll : public Commander {

class CommandPing : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
if (args_.size() == 1) {
*output = redis::SimpleString("PONG");
} else if (args_.size() == 2) {
Expand All @@ -201,7 +201,7 @@ class CommandPing : public Commander {

class CommandSelect : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
*output = redis::SimpleString("OK");
return Status::OK();
}
Expand Down Expand Up @@ -296,7 +296,7 @@ class CommandMemory : public CommandDisk {};

class CommandRole : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
srv->GetRoleInfo(output);
return Status::OK();
}
Expand Down Expand Up @@ -343,7 +343,7 @@ class CommandPerfLog : public Commander {
return Status::OK();
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
auto perf_log = srv->GetPerfLog();
if (subcommand_ == "len") {
*output = redis::Integer(static_cast<int64_t>(perf_log->Size()));
Expand Down Expand Up @@ -380,7 +380,7 @@ class CommandSlowlog : public Commander {
return Status::OK();
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
auto slowlog = srv->GetSlowLog();
if (subcommand_ == "reset") {
slowlog->Reset();
Expand Down Expand Up @@ -527,7 +527,7 @@ class CommandClient : public Commander {

class CommandMonitor : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
conn->Owner()->BecomeMonitorConn(conn);
*output = redis::SimpleString("OK");
return Status::OK();
Expand All @@ -536,7 +536,7 @@ class CommandMonitor : public Commander {

class CommandShutdown : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, Connection *conn, [[maybe_unused]] std::string *output) override {
if (!conn->IsAdmin()) {
return {Status::RedisExecErr, errAdminPermissionRequired};
}
Expand All @@ -551,7 +551,7 @@ class CommandShutdown : public Commander {

class CommandQuit : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
conn->EnableFlag(redis::Connection::kCloseAfterReply);
*output = redis::SimpleString("OK");
return Status::OK();
Expand Down Expand Up @@ -652,7 +652,7 @@ class CommandDebug : public Commander {

class CommandCommand : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
if (args_.size() == 1) {
CommandTable::GetAllCommandsInfo(output);
} else {
Expand Down Expand Up @@ -697,15 +697,15 @@ class CommandCommand : public Commander {

class CommandEcho : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
*output = redis::BulkString(args_[1]);
return Status::OK();
}
};

class CommandTime : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
uint64_t now = util::GetTimeStampUS();
uint64_t s = now / 1000 / 1000; // unix time in seconds.
uint64_t us = now - (s * 1000 * 1000); // microseconds.
Expand Down Expand Up @@ -820,8 +820,8 @@ class CommandScan : public CommandScanBase {
public:
CommandScan() : CommandScanBase() {}

static std::string GenerateOutput(Server *srv, const Connection *conn, const std::vector<std::string> &keys,
const std::string &end_cursor) {
static std::string GenerateOutput(Server *srv, [[maybe_unused]] const Connection *conn,
const std::vector<std::string> &keys, const std::string &end_cursor) {
std::vector<std::string> list;
if (!end_cursor.empty()) {
list.emplace_back(
Expand Down Expand Up @@ -1011,7 +1011,7 @@ class CommandSlaveOf : public Commander {

class CommandStats : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override {
std::string stats_json = srv->GetRocksDBStatsJson();
*output = redis::BulkString(stats_json);
return Status::OK();
Expand Down Expand Up @@ -1210,7 +1210,7 @@ class CommandApplyBatch : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *svr, Connection *conn, std::string *output) override {
Status Execute(Server *svr, [[maybe_unused]] Connection *conn, std::string *output) override {
size_t size = raw_batch_.size();
auto options = svr->storage->DefaultWriteOptions();
options.low_pri = low_pri_;
Expand Down
Loading

0 comments on commit fa3290c

Please sign in to comment.