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

Add nodiscard attribute to Status and StatusOr #1193

Merged
merged 2 commits into from
Dec 18, 2022
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ add_library(kvrocks_objs OBJECT ${KVROCKS_SRCS})

target_include_directories(kvrocks_objs PUBLIC src src/common ${PROJECT_BINARY_DIR})
target_compile_features(kvrocks_objs PUBLIC cxx_std_17)
# TODO: Add -Werror=unused-result to compile options
target_compile_options(kvrocks_objs PUBLIC -Wall -Wpedantic -Wsign-compare -Wreturn-type -fno-omit-frame-pointer)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(kvrocks_objs PUBLIC -Wno-pedantic)
Expand Down
4 changes: 2 additions & 2 deletions src/common/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <type_traits>
#include <utility>

class Status {
class [[nodiscard]] Status {
public:
enum Code : unsigned char {
cOK = 0,
Expand Down Expand Up @@ -121,7 +121,7 @@ template <typename T>
struct IsStatusOr<StatusOr<T>> : std::integral_constant<bool, true> {};

template <typename T>
struct StatusOr { // NOLINT
struct [[nodiscard]] StatusOr { // NOLINT
static_assert(!std::is_same<T, Status>::value, "value_type cannot be Status");
static_assert(!std::is_same<T, Status::Code>::value, "value_type cannot be Status::Code");
static_assert(!IsStatusOr<T>::value, "value_type cannot be StatusOr");
Expand Down
12 changes: 3 additions & 9 deletions utils/kvrocks2redis/writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,16 @@ Writer::~Writer() {
}

Status Writer::Write(const std::string &ns, const std::vector<std::string> &aofs) {
auto s = GetAofFd(ns);
if (!s.IsOK()) {
return Status(Status::NotOK, s.Msg());
}
GET_OR_RET(GetAofFd(ns));
for (const auto &aof : aofs) {
Util::Write(aof_fds_[ns], aof);
GET_OR_RET(Util::Write(aof_fds_[ns], aof));
}

return Status::OK();
}

Status Writer::FlushDB(const std::string &ns) {
auto s = GetAofFd(ns, true);
if (!s.IsOK()) {
return Status(Status::NotOK, s.Msg());
}
GET_OR_RET(GetAofFd(ns, true));

return Status::OK();
}
Expand Down