From 148f75f62a4df2daa39ee271c6362bcbd01b2b4f Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 25 Nov 2024 14:32:30 +0100 Subject: [PATCH 1/3] split GCC warnings in CMake --- CMakeLists.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3fcf4ba..c7ccfe6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,18 @@ function(add_compile_options_safe FLAG) endfunction() if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - add_compile_options(-Wall -Wextra -pedantic -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wshadow -Wundef -Wold-style-cast -Wno-multichar) + add_compile_options(-Wall) + add_compile_options(-Wextra) + add_compile_options(-pedantic) + add_compile_options(-Wcast-qual) + add_compile_options(-Wfloat-equal) + add_compile_options(-Wmissing-declarations) + add_compile_options(-Wmissing-format-attribute) + add_compile_options(-Wredundant-decls) + add_compile_options(-Wshadow) + add_compile_options(-Wundef) + add_compile_options(-Wold-style-cast) + add_compile_options(-Wno-multichar) elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") add_compile_definitions(_CRT_SECURE_NO_WARNINGS) elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") From 14cb0ddaa4b02523ee838720a35c183fdf34fbe6 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 25 Nov 2024 14:36:29 +0100 Subject: [PATCH 2/3] aligned GCC warnings with Cppcheck --- CMakeLists.txt | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7ccfe6d..672e63bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,18 +19,24 @@ function(add_compile_options_safe FLAG) endfunction() if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + add_compile_options(-pedantic) add_compile_options(-Wall) add_compile_options(-Wextra) - add_compile_options(-pedantic) - add_compile_options(-Wcast-qual) - add_compile_options(-Wfloat-equal) - add_compile_options(-Wmissing-declarations) - add_compile_options(-Wmissing-format-attribute) - add_compile_options(-Wredundant-decls) - add_compile_options(-Wshadow) + add_compile_options(-Wcast-qual) # Cast for removing type qualifiers + add_compile_options(-Wfloat-equal) # Floating values used in equality comparisons + add_compile_options(-Wmissing-declarations) # If a global function is defined without a previous declaration + add_compile_options(-Wmissing-format-attribute) # + add_compile_options(-Wno-long-long) + add_compile_options(-Wpacked) # + add_compile_options(-Wredundant-decls) # if anything is declared more than once in the same scope add_compile_options(-Wundef) - add_compile_options(-Wold-style-cast) + add_compile_options(-Wno-missing-braces) + add_compile_options(-Wno-sign-compare) add_compile_options(-Wno-multichar) + add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class + + add_compile_options(-Wsuggest-attribute=noreturn) + add_compile_options_safe(-Wuseless-cast) elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") add_compile_definitions(_CRT_SECURE_NO_WARNINGS) elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") From fcd2a176f9234374e2d8a5ead469487df445253a Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 25 Nov 2024 14:36:47 +0100 Subject: [PATCH 3/3] test.cpp: fixed `-Wuseless-cast` GCC warnings --- test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test.cpp b/test.cpp index 187b7ec6..86e6ddc8 100644 --- a/test.cpp +++ b/test.cpp @@ -279,9 +279,9 @@ static void characterLiteral() #ifdef __GNUC__ // BEGIN Implementation-specific results - ASSERT_EQUALS(static_cast('AB'), simplecpp::characterLiteralToLL("'AB'")); - ASSERT_EQUALS(static_cast('ABC'), simplecpp::characterLiteralToLL("'ABC'")); - ASSERT_EQUALS(static_cast('ABCD'), simplecpp::characterLiteralToLL("'ABCD'")); + ASSERT_EQUALS('AB', simplecpp::characterLiteralToLL("'AB'")); + ASSERT_EQUALS('ABC', simplecpp::characterLiteralToLL("'ABC'")); + ASSERT_EQUALS('ABCD', simplecpp::characterLiteralToLL("'ABCD'")); ASSERT_EQUALS('\134t', simplecpp::characterLiteralToLL("'\\134t'")); // cppcheck ticket #7452 // END Implementation-specific results #endif