From 7ba33ac4579849eafd9f1f0988c042291af4fe04 Mon Sep 17 00:00:00 2001 From: Brian Szmyd Date: Wed, 4 Oct 2023 15:06:20 -0700 Subject: [PATCH] Fix warnings --- CMakeLists.txt | 2 + cmake/Flags.cmake | 130 +++++++++++++++++++ src/CMakeLists.txt | 2 + src/lib/grpc_client.cpp | 2 +- src/lib/grpc_factory.cpp | 2 +- src/lib/logger.hpp | 13 +- src/lib/mesg_client.cpp | 2 +- src/lib/service.cpp | 4 +- src/lib/utils.hpp | 8 +- src/tests/jungle_logstore/CMakeLists.txt | 2 + src/tests/jungle_logstore/jungle_log_store.h | 2 +- src/tests/test_state_machine.h | 8 +- 12 files changed, 156 insertions(+), 21 deletions(-) create mode 100644 cmake/Flags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7114ad3..879ad9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.10) project(nuraft_mesg) enable_testing() +include (cmake/Flags.cmake) + set(CMAKE_CXX_STANDARD 20) if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) diff --git a/cmake/Flags.cmake b/cmake/Flags.cmake new file mode 100644 index 0000000..cbf691f --- /dev/null +++ b/cmake/Flags.cmake @@ -0,0 +1,130 @@ +#################################################################################################################################### +# add_flags(Flags ) +# +# The Flags argument contains the flag(s) to add +# +# The argument contains the languages the flag(s) apply to; the default is "C CXX". +# +# The argument contains the configurations to add the flag(s) to; the default is just the global flags. If +# specific configuration(s) are given then it is written to those only and not the global default +function(add_flags Flags) + set(options) + set(oneValueArgs Languages Configurations) + set(multiValueArgs) + cmake_parse_arguments(add_flags "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT Flags) + message(ERROR "Add Flags: Flags cannot be empty.") + endif() + + #set default languages and convert to list + if(NOT add_flags_Languages) + set(add_flags_Languages "C CXX") + endif() + separate_arguments(languages UNIX_COMMAND "${add_flags_Languages}") + + #set default configurations and convert to list + if(NOT add_flags_Configurations) + else() + separate_arguments(configurations UNIX_COMMAND "${add_flags_Configurations}") + endif() + + if(DEBUG_CMAKE) + message(STATUS "Add Flags:") + message(STATUS "Flags - ${Flags}") + message(STATUS "Languages - ${add_flags_Languages}") + if(DEFINED configurations) + message(STATUS "Configurations - ${add_flags_Configurations}") + else() + message(STATUS "Configurations - Global") + endif() + endif() + + foreach(language ${languages}) + string(TOUPPER "${language}" upper_language) + if(DEFINED configurations) + foreach(configuration ${configurations}) + string(TOUPPER "${configuration}" upper_configuration) + if(NOT CMAKE_${upper_language}_FLAGS_${upper_configuration}) + string(STRIP "${Flags}" CMAKE_MODIFIED_FLAGS) + else() + set(CMAKE_MODIFIED_FLAGS "${CMAKE_${upper_language}_FLAGS_${upper_configuration}} ${Flags}") + endif() + string(STRIP "${CMAKE_MODIFIED_FLAGS}" CMAKE_MODIFIED_FLAGS) + string(REGEX REPLACE "[ ]+" " " CMAKE_MODIFIED_FLAGS "${CMAKE_MODIFIED_FLAGS}") + set(CMAKE_${upper_language}_FLAGS_${upper_configuration} "${CMAKE_MODIFIED_FLAGS}" PARENT_SCOPE) + endforeach() + else() + if(NOT CMAKE_${upper_language}_FLAGS) + string(STRIP "${Flags}" CMAKE_MODIFIED_FLAGS) + else() + set(CMAKE_MODIFIED_FLAGS "${CMAKE_${upper_language}_FLAGS} ${Flags}") + endif() + string(STRIP "${CMAKE_MODIFIED_FLAGS}" CMAKE_MODIFIED_FLAGS) + string(REGEX REPLACE "[ ]+" " " CMAKE_MODIFIED_FLAGS "${CMAKE_MODIFIED_FLAGS}") + set(CMAKE_${upper_language}_FLAGS "${CMAKE_MODIFIED_FLAGS}" PARENT_SCOPE) + endif() + endforeach() +endfunction(add_flags) + +#################################################################################################################################### +# remove_flag(Flag ) +# +# The Flag argument contains the regex of the flag to remove +# +# The argument contains the languages the flag(s) apply to; the default is "C CXX". +# +# The argument contains the configurations to remove the flag(s) from; the default is the global flags and the +# individual build configuration flags of "Debug, Release, ReleaseWithDebInfo, MinSizedRelease". If specific configuration(s) are +# given then it is removed from the those only and the global. +function(remove_flag Flag) + set(options) + set(oneValueArgs Languages Configurations) + set(multiValueArgs) + cmake_parse_arguments(remove_flag "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT Flag) + message(ERROR "Remove Flag: Flag cannot be empty.") + endif() + + #set default languages and convert to list + if(NOT remove_flag_Languages) + set(remove_flag_Languages "C CXX") + endif() + separate_arguments(languages UNIX_COMMAND "${remove_flag_Languages}") + + #set default configurations and convert to list + if(NOT remove_flag_Configurations) + set(remove_flag_Configurations "Debug Release RelWithDebInfo MinSizedRelease") + endif() + separate_arguments(configurations UNIX_COMMAND "${remove_flag_Configurations}") + + if(DEBUG_CMAKE) + message(STATUS "Remove Flag:") + message(STATUS "Flag - ${Flag}") + message(STATUS "Languages - ${remove_flag_Languages}") + message(STATUS "Configurations - ${remove_flag_Configurations}") + endif() + + foreach(language ${languages}) + string(TOUPPER "${language}" upper_language) + # remove from configurations + foreach(configuration ${configurations}) + string(TOUPPER "${configuration}" upper_configuration) + if(CMAKE_${upper_language}_FLAGS_${upper_configuration}) + string(REGEX REPLACE "${Flag}" "" CMAKE_MODIFIED_FLAGS "${CMAKE_${upper_language}_FLAGS_${upper_configuration}}") + string(STRIP "${CMAKE_MODIFIED_FLAGS}" CMAKE_MODIFIED_FLAGS) + string(REGEX REPLACE "[ ]+" " " CMAKE_MODIFIED_FLAGS "${CMAKE_MODIFIED_FLAGS}") + set(CMAKE_${upper_language}_FLAGS_${upper_configuration} "${CMAKE_MODIFIED_FLAGS}" PARENT_SCOPE) + endif() + endforeach() + + #remove from global + if(CMAKE_${upper_language}_FLAGS) + string(REGEX REPLACE "${Flag}" "" CMAKE_MODIFIED_GLOBAL_FLAGS "${CMAKE_${upper_language}_FLAGS}") + string(STRIP "${CMAKE_MODIFIED_GLOBAL_FLAGS}" CMAKE_MODIFIED_GLOBAL_FLAGS) + string(REGEX REPLACE "[ ]+" " " CMAKE_MODIFIED_FLAGS "${CMAKE_MODIFIED_FLAGS}") + set(CMAKE_${upper_language}_FLAGS "${CMAKE_MODIFIED_GLOBAL_FLAGS}" PARENT_SCOPE) + endif() + endforeach() +endfunction(remove_flag) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0bfa2f0..0353621 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,8 @@ include(${sisl_INCLUDE_DIRS}/../cmake/settings_gen.cmake) add_subdirectory (proto) +add_flags("-Wall -Wextra -Werror -Wpedantic") + add_library(${PROJECT_NAME}) target_sources(${PROJECT_NAME} PRIVATE lib/grpc_client.cpp diff --git a/src/lib/grpc_client.cpp b/src/lib/grpc_client.cpp index 772a6d9..8c8dfe8 100644 --- a/src/lib/grpc_client.cpp +++ b/src/lib/grpc_client.cpp @@ -68,7 +68,7 @@ inline std::shared_ptr< nuraft::resp_msg > toResponse(RaftMessage const& raft_ms std::atomic_uint64_t grpc_base_client::_client_counter = 0ul; void grpc_base_client::send(std::shared_ptr< nuraft::req_msg >& req, nuraft::rpc_handler& complete, - uint64_t timeout_ms) { + uint64_t) { assert(req && complete); RaftMessage grpc_request; grpc_request.set_allocated_base(fromBaseRequest(*req)); diff --git a/src/lib/grpc_factory.cpp b/src/lib/grpc_factory.cpp index c69015f..0b578e0 100644 --- a/src/lib/grpc_factory.cpp +++ b/src/lib/grpc_factory.cpp @@ -134,7 +134,7 @@ grpc_factory::grpc_factory(int const cli_thread_count, std::string const& name) } class grpc_error_client : public grpc_base_client { - void send(RaftMessage const& message, handle_resp complete) override { + void send(RaftMessage const&, handle_resp complete) override { auto null_msg = RaftMessage(); auto status = ::grpc::Status(::grpc::ABORTED, "Bad connection"); complete(null_msg, status); diff --git a/src/lib/logger.hpp b/src/lib/logger.hpp index c886335..fba94cb 100644 --- a/src/lib/logger.hpp +++ b/src/lib/logger.hpp @@ -42,24 +42,21 @@ class nuraft_mesg_logger : public ::nuraft::logger { [[fallthrough]]; case 2: { LOGERRORMOD(nuraft, "{}", mesg); + LOGERRORMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg); } break; - ; case 3: { LOGWARNMOD(nuraft, "{}", mesg); + LOGWARNMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg); } break; - ; case 4: { - LOGINFOMOD_USING_LOGGER(nuraft, _custom_logger, "INFO {}", mesg); + LOGINFOMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg); } break; - ; case 5: { - LOGDEBUGMOD_USING_LOGGER(nuraft, _custom_logger, "DEBUG {}", mesg); + LOGDEBUGMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg); } break; - ; default: { - LOGTRACEMOD_USING_LOGGER(nuraft, _custom_logger, "TRACE {}", mesg); + LOGTRACEMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg); } break; - ; } } }; diff --git a/src/lib/mesg_client.cpp b/src/lib/mesg_client.cpp index e14487a..689a17c 100644 --- a/src/lib/mesg_client.cpp +++ b/src/lib/mesg_client.cpp @@ -175,7 +175,7 @@ nuraft::cmd_result_code group_factory::create_client(peer_id_t const& client, nuraft::ptr< nuraft::rpc_client >& raft_client) { LOGDEBUGMOD(nuraft_mesg, "Creating client to {}", client); auto endpoint = lookupEndpoint(client); - if (endpoint.empty()) nuraft::BAD_REQUEST; + if (endpoint.empty()) return nuraft::BAD_REQUEST; LOGDEBUGMOD(nuraft_mesg, "Creating client for [{}] @ [{}]", client, endpoint); raft_client = diff --git a/src/lib/service.cpp b/src/lib/service.cpp index e21fc83..65090c1 100644 --- a/src/lib/service.cpp +++ b/src/lib/service.cpp @@ -23,7 +23,7 @@ SISL_OPTION_GROUP(nuraft_mesg, (resp)->when_ready( \ [p = std::make_shared< decltype(p) >(std::move(p))]( \ nuraft::cmd_result< nuraft::ptr< nuraft::buffer >, nuraft::ptr< std::exception > >& result, \ - auto& e) mutable { \ + auto&) mutable { \ if (nuraft::cmd_result_code::OK != result.get_result_code()) \ p->setValue(folly::makeUnexpected(result.get_result_code())); \ else \ @@ -252,7 +252,7 @@ class msg_group_listner : public nuraft::rpc_listener { msg_group_listner(std::shared_ptr< msg_service > svc, group_id_t const& group) : _svc(svc), _group(group) {} ~msg_group_listner() { _svc->shutdown_for(_group); } - void listen(nuraft::ptr< nuraft::msg_handler >& handler) override { + void listen(nuraft::ptr< nuraft::msg_handler >&) override { LOGINFOMOD(nuraft_mesg, "Begin listening on {}", _group); } void stop() override { LOGINFOMOD(nuraft_mesg, "Stop {}", _group); } diff --git a/src/lib/utils.hpp b/src/lib/utils.hpp index d8a2291..72220a3 100644 --- a/src/lib/utils.hpp +++ b/src/lib/utils.hpp @@ -32,7 +32,7 @@ inline RCMsgBase* fromBaseRequest(nuraft::msg_base const& rcbase) { return base; } -static void serialize_to_byte_buffer(grpc::ByteBuffer& cli_byte_buf, io_blob_list_t const& cli_buf) { +[[maybe_unused]] static void serialize_to_byte_buffer(grpc::ByteBuffer& cli_byte_buf, io_blob_list_t const& cli_buf) { folly::small_vector< grpc::Slice, 4 > slices; for (auto const& blob : cli_buf) { slices.emplace_back(blob.bytes, blob.size, grpc::Slice::STATIC_SLICE); @@ -42,7 +42,8 @@ static void serialize_to_byte_buffer(grpc::ByteBuffer& cli_byte_buf, io_blob_lis cli_byte_buf.Swap(&tmp); } -static grpc::Status deserialize_from_byte_buffer(grpc::ByteBuffer const& cli_byte_buf, sisl::io_blob& cli_buf) { +[[maybe_unused]] static grpc::Status deserialize_from_byte_buffer(grpc::ByteBuffer const& cli_byte_buf, + sisl::io_blob& cli_buf) { grpc::Slice slice; auto status = cli_byte_buf.TrySingleSlice(&slice); if (!status.ok()) { return status; } @@ -53,7 +54,8 @@ static grpc::Status deserialize_from_byte_buffer(grpc::ByteBuffer const& cli_byt // generic rpc server looks up rpc name in a map and calls the corresponding callback. To avoid another lookup in this // layer, we registed one callback for each (group_id, request_name) pair. The rpc_name is their concatenation. -static std::string get_generic_method_name(std::string const& request_name, group_id_t const& group_id) { +[[maybe_unused]] static std::string get_generic_method_name(std::string const& request_name, + group_id_t const& group_id) { return fmt::format("{}|{}", request_name, group_id); } diff --git a/src/tests/jungle_logstore/CMakeLists.txt b/src/tests/jungle_logstore/CMakeLists.txt index 6cb942b..dc959d4 100644 --- a/src/tests/jungle_logstore/CMakeLists.txt +++ b/src/tests/jungle_logstore/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required (VERSION 3.11) file (GLOB LIBRARY_SOURCES *.cc) +add_flags("-w") + if (APPLE) set(OPEN_MEMSTREAM open_memstream.c) message(STATUS "APPLE: Use custom ${OPEN_MEMSTREAM}") diff --git a/src/tests/jungle_logstore/jungle_log_store.h b/src/tests/jungle_logstore/jungle_log_store.h index e6f5039..455aedc 100644 --- a/src/tests/jungle_logstore/jungle_log_store.h +++ b/src/tests/jungle_logstore/jungle_log_store.h @@ -54,7 +54,7 @@ class jungle_log_store : public log_store { const Options& opt = jungle_log_store::Options()); ~jungle_log_store(); - __nocopy__(jungle_log_store); + __nocopy__(jungle_log_store) public: /** diff --git a/src/tests/test_state_machine.h b/src/tests/test_state_machine.h index fa31d4f..40fa0d5 100644 --- a/src/tests/test_state_machine.h +++ b/src/tests/test_state_machine.h @@ -54,14 +54,14 @@ class test_state_machine : public state_machine { LOGINFO("Rollback message [{}] op: {}", log_idx, j_obj.at("op_type").get< int >()); } - virtual void save_snapshot_data(snapshot& s, const ulong offset, buffer& data) {} - virtual bool apply_snapshot(snapshot& s) { return true; } + virtual void save_snapshot_data(snapshot&, const ulong, buffer&) {} + virtual bool apply_snapshot(snapshot&) { return true; } - virtual int read_snapshot_data(snapshot& s, const ulong offset, buffer& data) { return 0; } + virtual int read_snapshot_data(snapshot&, const ulong, buffer&) { return 0; } virtual ptr< snapshot > last_snapshot() { return ptr< snapshot >(); } - virtual void create_snapshot(snapshot& s, async_result< bool >::handler_type& when_done) {} + virtual void create_snapshot(snapshot&, async_result< bool >::handler_type&) {} virtual ulong last_commit_index() { auto_lock(lock_);