From d5be8cad97e8582feefc7b8445c02e796bcd98c1 Mon Sep 17 00:00:00 2001
From: Patrick Ziegler
Date: Mon, 4 Jan 2021 10:38:43 +0100
Subject: [PATCH] Add compiler warning for missing override specifier (#2341)
* build: Add -Wsuggest-override
We should always use the override specifier when overriding virtual
functions. This helps prevent errors when a subclass tries to create a
function with the same name as a virtual function in a super-class but
with a different purpose.
* clang-format
* Upload logs on failure
* Add override to unsupported.hpp
* cmake: Make -Wsuggest-override flag conditional
---
.github/workflows/ci.yml | 9 ++++++
cmake/cxx.cmake | 6 ++++
include/components/bar.hpp | 30 +++++++++---------
include/components/controller.hpp | 22 +++++++-------
include/components/renderer.hpp | 32 ++++++++++----------
include/components/screen.hpp | 6 ++--
include/events/signal_receiver.hpp | 4 +--
include/modules/battery.hpp | 2 +-
include/modules/bspwm.hpp | 2 +-
include/modules/i3.hpp | 2 +-
include/modules/ipc.hpp | 2 +-
include/modules/meta/base.hpp | 20 ++++++------
include/modules/meta/event_module.hpp | 4 +--
include/modules/meta/inotify_module.hpp | 4 +--
include/modules/meta/static_module.hpp | 4 +--
include/modules/meta/timer_module.hpp | 2 +-
include/modules/script.hpp | 4 +--
include/modules/unsupported.hpp | 22 +++++++-------
include/modules/xbacklight.hpp | 2 +-
include/modules/xkeyboard.hpp | 6 ++--
include/modules/xwindow.hpp | 2 +-
include/modules/xworkspaces.hpp | 2 +-
include/tags/parser.hpp | 2 +-
include/utils/file.hpp | 6 ++--
include/x11/background_manager.hpp | 11 +++----
include/x11/connection.hpp | 9 +++---
include/x11/tray_manager.hpp | 28 ++++++++---------
tests/unit_tests/components/command_line.cpp | 28 ++++++++---------
28 files changed, 145 insertions(+), 128 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index db2d2162..bdf02c2a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -111,3 +111,12 @@ jobs:
make check
cd $POLYBAR_DIR
bash <(curl -s https://codecov.io/bash) -F unittests -a "-ap" -Z
+ - name: Upload Logs
+ if: failure()
+ uses: actions/upload-artifact@v2
+ with:
+ name: cmake
+ path: |
+ build/CMakeFiles/CMakeError.log
+ build/CMakeFiles/CMakeOutput.log
+ retention-days: 5
diff --git a/cmake/cxx.cmake b/cmake/cxx.cmake
index 751e1a60..b271e4b8 100644
--- a/cmake/cxx.cmake
+++ b/cmake/cxx.cmake
@@ -22,9 +22,15 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(THREADS_PREFER_PTHREAD_FLAG ON)
# Compiler flags
+include(CheckCXXCompilerFlag)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic")
+check_cxx_compiler_flag("-Wsuggest-override" HAS_SUGGEST_OVERRIDE)
+if (HAS_SUGGEST_OVERRIDE)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override")
+endif()
+unset(HAS_SUGGEST_OVERRIDE)
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
# Need dprintf() for FreeBSD 11.1 and older
diff --git a/include/components/bar.hpp b/include/components/bar.hpp
index 60416d1d..0c554678 100644
--- a/include/components/bar.hpp
+++ b/include/components/bar.hpp
@@ -86,23 +86,23 @@ class bar : public xpp::event::sink {
}
protected:
- void handle(const evt::randr_screen_change_notify& evt);
+ void handle(const evt::randr_screen_change_notify& evt) override;
private:
connection& m_connection;
@@ -45,7 +45,9 @@ class screen : public xpp::event::sink {
xcb_window_t m_proxy{XCB_NONE};
vector m_monitors;
- struct size m_size {0U, 0U};
+ struct size m_size {
+ 0U, 0U
+ };
bool m_sigraised{false};
bool have_monitors_changed() const;
diff --git a/include/events/signal_receiver.hpp b/include/events/signal_receiver.hpp
index 9f2a8055..71cd6013 100644
--- a/include/events/signal_receiver.hpp
+++ b/include/events/signal_receiver.hpp
@@ -1,9 +1,9 @@
#pragma once
#include