From 32c1049f74cfe3eae7d87313bd4dcb91dea2b511 Mon Sep 17 00:00:00 2001 From: 13015517713 <2430278602@qq.com> Date: Mon, 22 Apr 2024 17:54:49 +0800 Subject: [PATCH] fix unused-variable error for lower gcc version due to structure bindings --- 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 f131bccddf4..a7abf02298b 100644 --- a/src/server/server.cc +++ b/src/server/server.cc @@ -1633,7 +1633,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) {