From 60b36e7a70beea35bb4eedde8bb550e92d2ae532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Spr=C3=B6=C3=9Fig?= Date: Mon, 26 Oct 2020 21:51:52 +0100 Subject: [PATCH] Fix Clang/GCC warnings and update compile options (#39) --- CMakeLists.txt | 35 ++++++++++++++++++++++++++++++++++- src/qtpromise/qpromise_p.h | 8 ++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32e17b6..7967e59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,12 +33,45 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") -Wpedantic -Wall -Wextra + -Wconversion - -Wsign-conversion + -Wdouble-promotion + -Wformat=2 + -Wlogical-op + -Wmissing-noreturn -Wold-style-cast +# -Wshadow # disabled due to many findings in the current code + -Wsign-conversion + -Wswitch-default -Wunused-local-typedefs +# -Wuseless-cast # disabled due to Qt's moc warnings + -pedantic-errors ) + + # https://github.com/Barro/compiler-warnings/blob/master/gcc/warnings-gcc-6.txt + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6) + add_compile_options( + -Wduplicated-cond + ) + endif() + + # https://github.com/Barro/compiler-warnings/blob/master/gcc/warnings-gcc-7.txt + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7) + add_compile_options( + -Wduplicated-branches + ) + endif() +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # https://clang.llvm.org/docs/DiagnosticsReference.html + add_compile_options( + -Wall + -Wextra + -Wpedantic + + -Wsuggest-destructor-override + -Wsuggest-override + ) elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") # https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level add_compile_options( diff --git a/src/qtpromise/qpromise_p.h b/src/qtpromise/qpromise_p.h index 681bb2b..33eff9f 100644 --- a/src/qtpromise/qpromise_p.h +++ b/src/qtpromise/qpromise_p.h @@ -52,7 +52,7 @@ static void qtpromise_defer(F&& f, const QPointer& thread) { Event(FType&& f) : QEvent{QEvent::None}, m_f{std::move(f)} { } Event(const FType& f) : QEvent{QEvent::None}, m_f{f} { } - ~Event() { m_f(); } + ~Event() override { m_f(); } FType m_f; }; @@ -113,7 +113,7 @@ public: PromiseError() { } PromiseError(const std::exception_ptr& exception) : m_data{exception} { } - void rethrow() const { std::rethrow_exception(m_data); } + Q_NORETURN void rethrow() const { std::rethrow_exception(m_data); } bool isNull() const { return m_data == nullptr; } private: @@ -329,8 +329,8 @@ struct PromiseCatcher return [=](const PromiseError& error) { try { error.rethrow(); - } catch (const TArg& error) { - PromiseDispatch::call(resolve, reject, handler, error); + } catch (const TArg& argError) { + PromiseDispatch::call(resolve, reject, handler, argError); } catch (...) { reject(std::current_exception()); }