From 7245db470400214c94c12fc4856283557b61bc35 Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Thu, 22 Oct 2020 17:31:21 +0300 Subject: [PATCH] Enable -Wsuggest-override if supported by the compiler. --- CMakeLists.txt | 5 ++ include/wsrep/condition_variable.hpp | 7 +-- include/wsrep/mutex.hpp | 14 ++--- src/wsrep_provider_v26.hpp | 80 ++++++++++++++++------------ 4 files changed, 62 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a33d22..740f538 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ endif() include(CheckIncludeFile) include(CheckLibraryExists) +include(CheckCXXCompilerFlag) # Options @@ -72,6 +73,10 @@ endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wconversion") # CXX flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Woverloaded-virtual -Wconversion -g") +check_cxx_compiler_flag("-Wsuggest-override" HAVE_SUGGEST_OVERRIDE) +if (HAVE_SUGGEST_OVERRIDE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override") +endif() if (WSREP_LIB_STRICT_BUILD_FLAGS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++") diff --git a/include/wsrep/condition_variable.hpp b/include/wsrep/condition_variable.hpp index aa0a34a..b929147 100644 --- a/include/wsrep/condition_variable.hpp +++ b/include/wsrep/condition_variable.hpp @@ -20,6 +20,7 @@ #ifndef WSREP_CONDITION_VARIABLE_HPP #define WSREP_CONDITION_VARIABLE_HPP +#include "compiler.hpp" #include "lock.hpp" #include @@ -59,17 +60,17 @@ namespace wsrep ::abort(); } } - void notify_one() + void notify_one() WSREP_OVERRIDE { (void)pthread_cond_signal(&cond_); } - void notify_all() + void notify_all() WSREP_OVERRIDE { (void)pthread_cond_broadcast(&cond_); } - void wait(wsrep::unique_lock& lock) + void wait(wsrep::unique_lock& lock) WSREP_OVERRIDE { if (pthread_cond_wait( &cond_, diff --git a/include/wsrep/mutex.hpp b/include/wsrep/mutex.hpp index 9065983..9b0173b 100644 --- a/include/wsrep/mutex.hpp +++ b/include/wsrep/mutex.hpp @@ -20,15 +20,17 @@ #ifndef WSREP_MUTEX_HPP #define WSREP_MUTEX_HPP +#include "compiler.hpp" #include "exception.hpp" + #include namespace wsrep { - //! - //! - //! + /** + * Mutex interface. + */ class mutex { public: @@ -61,7 +63,7 @@ namespace wsrep if (pthread_mutex_destroy(&mutex_)) ::abort(); } - void lock() + void lock() WSREP_OVERRIDE { if (pthread_mutex_lock(&mutex_)) { @@ -69,7 +71,7 @@ namespace wsrep } } - void unlock() + void unlock() WSREP_OVERRIDE { if (pthread_mutex_unlock(&mutex_)) { @@ -77,7 +79,7 @@ namespace wsrep } } - void* native() + void* native() WSREP_OVERRIDE { return &mutex_; } diff --git a/src/wsrep_provider_v26.hpp b/src/wsrep_provider_v26.hpp index df48c81..47a91ce 100644 --- a/src/wsrep_provider_v26.hpp +++ b/src/wsrep_provider_v26.hpp @@ -37,62 +37,72 @@ namespace wsrep ~wsrep_provider_v26(); enum wsrep::provider::status connect(const std::string&, const std::string&, const std::string&, - bool); - int disconnect(); - int capabilities() const; + bool) WSREP_OVERRIDE; + int disconnect() WSREP_OVERRIDE; + int capabilities() const WSREP_OVERRIDE; - int desync(); - int resync(); - wsrep::seqno pause(); - int resume(); + int desync() WSREP_OVERRIDE; + int resync() WSREP_OVERRIDE; + wsrep::seqno pause() WSREP_OVERRIDE; + int resume() WSREP_OVERRIDE; - enum wsrep::provider::status run_applier(wsrep::high_priority_service*); - int start_transaction(wsrep::ws_handle&) { return 0; } enum wsrep::provider::status - assign_read_view(wsrep::ws_handle&, const wsrep::gtid*); - int append_key(wsrep::ws_handle&, const wsrep::key&); + run_applier(wsrep::high_priority_service*) WSREP_OVERRIDE; + int start_transaction(wsrep::ws_handle&) WSREP_OVERRIDE { return 0; } enum wsrep::provider::status - append_data(wsrep::ws_handle&, const wsrep::const_buffer&); + assign_read_view(wsrep::ws_handle&, const wsrep::gtid*) WSREP_OVERRIDE; + int append_key(wsrep::ws_handle&, const wsrep::key&) WSREP_OVERRIDE; + enum wsrep::provider::status + append_data(wsrep::ws_handle&, const wsrep::const_buffer&) + WSREP_OVERRIDE; enum wsrep::provider::status certify(wsrep::client_id, wsrep::ws_handle&, int, - wsrep::ws_meta&); + wsrep::ws_meta&) WSREP_OVERRIDE; enum wsrep::provider::status bf_abort(wsrep::seqno, wsrep::transaction_id, - wsrep::seqno&); - enum wsrep::provider::status rollback(const wsrep::transaction_id); + wsrep::seqno&) WSREP_OVERRIDE; + enum wsrep::provider::status + rollback(const wsrep::transaction_id) WSREP_OVERRIDE; enum wsrep::provider::status commit_order_enter(const wsrep::ws_handle&, - const wsrep::ws_meta&); + const wsrep::ws_meta&) WSREP_OVERRIDE; int commit_order_leave(const wsrep::ws_handle&, const wsrep::ws_meta&, - const wsrep::mutable_buffer&); - int release(wsrep::ws_handle&); + const wsrep::mutable_buffer&) WSREP_OVERRIDE; + int release(wsrep::ws_handle&) WSREP_OVERRIDE; enum wsrep::provider::status replay(const wsrep::ws_handle&, - wsrep::high_priority_service*); + wsrep::high_priority_service*) + WSREP_OVERRIDE; enum wsrep::provider::status enter_toi(wsrep::client_id, const wsrep::key_array&, const wsrep::const_buffer&, wsrep::ws_meta&, - int); + int) + WSREP_OVERRIDE; enum wsrep::provider::status leave_toi(wsrep::client_id, - const wsrep::mutable_buffer&); + const wsrep::mutable_buffer&) + WSREP_OVERRIDE; std::pair - causal_read(int) const; - enum wsrep::provider::status wait_for_gtid(const wsrep::gtid&, int) const; - wsrep::gtid last_committed_gtid() const; - enum wsrep::provider::status sst_sent(const wsrep::gtid&, int); - enum wsrep::provider::status sst_received(const wsrep::gtid& gtid, int); - enum wsrep::provider::status enc_set_key(const wsrep::const_buffer& key); - std::vector status() const; - void reset_status(); - std::string options() const; - enum wsrep::provider::status options(const std::string&); - std::string name() const; - std::string version() const; - std::string vendor() const; - void* native() const; + causal_read(int) const WSREP_OVERRIDE; + enum wsrep::provider::status wait_for_gtid(const wsrep::gtid&, int) + const WSREP_OVERRIDE; + wsrep::gtid last_committed_gtid() const WSREP_OVERRIDE; + enum wsrep::provider::status sst_sent(const wsrep::gtid&, int) + WSREP_OVERRIDE; + enum wsrep::provider::status sst_received(const wsrep::gtid& gtid, int) + WSREP_OVERRIDE; + enum wsrep::provider::status enc_set_key(const wsrep::const_buffer& key) + WSREP_OVERRIDE; + std::vector status() const WSREP_OVERRIDE; + void reset_status() WSREP_OVERRIDE; + std::string options() const WSREP_OVERRIDE; + enum wsrep::provider::status options(const std::string&) WSREP_OVERRIDE; + std::string name() const WSREP_OVERRIDE; + std::string version() const WSREP_OVERRIDE; + std::string vendor() const WSREP_OVERRIDE; + void* native() const WSREP_OVERRIDE; private: wsrep_provider_v26(const wsrep_provider_v26&); wsrep_provider_v26& operator=(const wsrep_provider_v26);