From e780939689ff1b031a44640a00a91ecbd85e7439 Mon Sep 17 00:00:00 2001 From: detached <54363053+13015517713@users.noreply.github.com> Date: Mon, 22 Apr 2024 22:11:12 +0800 Subject: [PATCH] Fix unused-variable error for lower gcc version due to structure bindings (#2265) Co-authored-by: hulk --- CMakeLists.txt | 11 ++++++++++- src/server/server.cc | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d508d4ea41a..944b55090e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,7 +212,16 @@ 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-result -Werror=unused-variable) +target_compile_options(kvrocks_objs PUBLIC -Werror=unused-result) + +# disable unused-variable check on GCC < 8 due to the structure bindings +# https://gcc.gnu.org/bugzilla/show_bug.cgi?format=multiple&id=81767 +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8) + target_compile_options(kvrocks_objs PUBLIC -Wno-error=unused-variable) +else() + target_compile_options(kvrocks_objs PUBLIC -Werror=unused-variable) +endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(kvrocks_objs PUBLIC -Wno-pedantic) elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")) diff --git a/src/server/server.cc b/src/server/server.cc index 9408b90c6d9..e482aefb561 100644 --- a/src/server/server.cc +++ b/src/server/server.cc @@ -1636,7 +1636,7 @@ StatusOr> Server::LookupAndCreateCommand(const auto cmd = cmd_attr->factory(); cmd->SetAttributes(cmd_attr); - return cmd; + return std::move(cmd); } Status Server::ScriptExists(const std::string &sha) {