From 5f97637d5e84ee696d8a322c006fce89f4ea9357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 19 Apr 2020 22:34:03 +0200 Subject: [PATCH] Only suggest final when using non-LTO builds In LTO builds GCC issues the suggestion-warning from linking stage, when pragmas are already gone and do nothing. --- CMakeLists.txt | 27 ++++++++++--------- src/openrct2-ui/audio/AudioContext.cpp | 2 +- .../engines/opengl/OpenGLDrawingEngine.cpp | 2 +- src/openrct2/Context.cpp | 2 +- src/openrct2/GameStateSnapshots.cpp | 2 +- src/openrct2/actions/GameAction.h | 2 +- src/openrct2/actions/TrackPlaceAction.hpp | 2 +- src/openrct2/core/IStream.hpp | 10 +++++++ src/openrct2/drawing/X8DrawingEngine.h | 9 +++++++ 9 files changed, 40 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6de53dc522..46aa1c12bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,16 +122,6 @@ if (ENABLE_LIGHTFX) add_definitions(-D__ENABLE_LIGHTFX__) endif () -if (CXX_WARN_SUGGEST_FINAL_TYPES) - # Disable -Wsuggest-final-types via pragmas where due. - add_definitions(-D__WARN_SUGGEST_FINAL_TYPES__) -endif () - -if (CXX_WARN_SUGGEST_FINAL_METHODS) - # Disable -Wsuggest-final-methods via pragmas where due. - add_definitions(-D__WARN_SUGGEST_FINAL_METHODS__) -endif () - if (NOT DISABLE_DISCORD_RPC) if(EXISTS "${ROOT_DIR}/discord-rpc") # Don't build discord's examples, some of which are in C and do not honour @@ -202,8 +192,6 @@ if (MSVC) add_definitions(-DNOMINMAX) else () ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_NULL_DEREFERENCE -Wnull-dereference) - ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_SUGGEST_FINAL_TYPES -Wsuggest-final-types) - ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_SUGGEST_FINAL_METHODS -Wsuggest-final-methods) ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_SUGGEST_OVERRIDE -Wsuggest-override) ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_DUPLICATED_COND -Wduplicated-cond) ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_NON_VIRTUAL_DTOR -Wnon-virtual-dtor) @@ -224,6 +212,11 @@ else () # Do not enable for MinGW, as its headers contain redundant declarations of builtin functions ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls) endif () + # These have no workarounds available when building with LTO + if (NOT IPO_BUILD_ENABLED) + ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_SUGGEST_FINAL_TYPES -Wsuggest-final-types) + ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_SUGGEST_FINAL_METHODS -Wsuggest-final-methods) + endif () ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_IGNORED_QUALIFIERS -Wignored-qualifiers) # -Wstrict-overflow is only active when -fstrict-overflow is enabled, but -fstrict-overflow @@ -254,6 +247,16 @@ else () endif () endif () +if (CXX_WARN_SUGGEST_FINAL_TYPES) + # Disable -Wsuggest-final-types via pragmas where due. + add_definitions(-D__WARN_SUGGEST_FINAL_TYPES__) +endif () + +if (CXX_WARN_SUGGEST_FINAL_METHODS) + # Disable -Wsuggest-final-methods via pragmas where due. + add_definitions(-D__WARN_SUGGEST_FINAL_METHODS__) +endif () + # Include sub-projects include("${ROOT_DIR}/src/openrct2/CMakeLists.txt" NO_POLICY_SCOPE) include("${ROOT_DIR}/src/openrct2-cli/CMakeLists.txt" NO_POLICY_SCOPE) diff --git a/src/openrct2-ui/audio/AudioContext.cpp b/src/openrct2-ui/audio/AudioContext.cpp index c9e5833bc3..d9f08156f3 100644 --- a/src/openrct2-ui/audio/AudioContext.cpp +++ b/src/openrct2-ui/audio/AudioContext.cpp @@ -18,7 +18,7 @@ namespace OpenRCT2::Audio { - class AudioContext : public IAudioContext + class AudioContext final : public IAudioContext { private: IAudioMixer* _audioMixer = nullptr; diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp index 2e181b9569..4a092b1a63 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -172,7 +172,7 @@ public: } }; -class OpenGLDrawingEngine : public IDrawingEngine +class OpenGLDrawingEngine final : public IDrawingEngine { private: std::shared_ptr const _uiContext; diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index f29e418011..4e974ec484 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -79,7 +79,7 @@ using namespace OpenRCT2::Ui; namespace OpenRCT2 { - class Context : public IContext + class Context final : public IContext { private: // Dependencies diff --git a/src/openrct2/GameStateSnapshots.cpp b/src/openrct2/GameStateSnapshots.cpp index 4e8484e9bc..d53290125b 100644 --- a/src/openrct2/GameStateSnapshots.cpp +++ b/src/openrct2/GameStateSnapshots.cpp @@ -109,7 +109,7 @@ struct GameStateSnapshot_t } }; -struct GameStateSnapshots : public IGameStateSnapshots +struct GameStateSnapshots final : public IGameStateSnapshots { virtual void Reset() override final { diff --git a/src/openrct2/actions/GameAction.h b/src/openrct2/actions/GameAction.h index 349de000e5..ab3005901b 100644 --- a/src/openrct2/actions/GameAction.h +++ b/src/openrct2/actions/GameAction.h @@ -297,7 +297,7 @@ namespace GameActions return #cls; \ } \ }; \ - struct cls : public GameActionBase + struct cls final : public GameActionBase // clang-format on } // namespace GameActions diff --git a/src/openrct2/actions/TrackPlaceAction.hpp b/src/openrct2/actions/TrackPlaceAction.hpp index 74cccc448b..658d21be5e 100644 --- a/src/openrct2/actions/TrackPlaceAction.hpp +++ b/src/openrct2/actions/TrackPlaceAction.hpp @@ -74,7 +74,7 @@ public: _origin.direction &= 3; } - uint16_t GetActionFlags() const override + uint16_t GetActionFlags() const override final { return GameAction::GetActionFlags(); } diff --git a/src/openrct2/core/IStream.hpp b/src/openrct2/core/IStream.hpp index 815ed43063..d17e089a01 100644 --- a/src/openrct2/core/IStream.hpp +++ b/src/openrct2/core/IStream.hpp @@ -24,6 +24,12 @@ enum STREAM_SEEK_END }; +#ifdef __WARN_SUGGEST_FINAL_METHODS__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wsuggest-final-methods" +# pragma GCC diagnostic ignored "-Wsuggest-final-types" +#endif + /** * Represents a stream that can be read or written to. Implemented by types such as FileStream, NetworkStream or MemoryStream. */ @@ -199,6 +205,10 @@ interface IStream void WriteString(const std::string& string); }; +#ifdef __WARN_SUGGEST_FINAL_METHODS__ +# pragma GCC diagnostic pop +#endif + class IOException : public std::runtime_error { public: diff --git a/src/openrct2/drawing/X8DrawingEngine.h b/src/openrct2/drawing/X8DrawingEngine.h index 41228594b5..cb715d6783 100644 --- a/src/openrct2/drawing/X8DrawingEngine.h +++ b/src/openrct2/drawing/X8DrawingEngine.h @@ -85,7 +85,16 @@ namespace OpenRCT2 public: explicit X8DrawingEngine(const std::shared_ptr& uiContext); + +#ifdef __WARN_SUGGEST_FINAL_METHODS__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wsuggest-final-methods" +# pragma GCC diagnostic ignored "-Wsuggest-final-types" +#endif ~X8DrawingEngine() override; +#ifdef __WARN_SUGGEST_FINAL_METHODS__ +# pragma GCC diagnostic pop +#endif void Initialise() override; void Resize(uint32_t width, uint32_t height) override;