From d4a55a55549349594d54f61cf0b70f426a3135ea Mon Sep 17 00:00:00 2001
From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com>
Date: Wed, 22 May 2024 23:17:07 -0500
Subject: [PATCH] Build with -Wpedantic
---
.github/workflows/cmake-integration.yml | 24 ++++++++++++------------
CMakeLists.txt | 19 ++++++++++++-------
test/CMakeLists.txt | 2 ++
test/ctrace_demo.c | 3 +++
test/demo.cpp | 2 +-
test/integration.cpp | 6 +++---
6 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/.github/workflows/cmake-integration.yml b/.github/workflows/cmake-integration.yml
index fb60aa7..3ab9c04 100644
--- a/.github/workflows/cmake-integration.yml
+++ b/.github/workflows/cmake-integration.yml
@@ -21,7 +21,7 @@ jobs:
cp -rv cpptrace/test/fetchcontent-integration .
mkdir fetchcontent-integration/build
cd fetchcontent-integration/build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG=$tag -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG=$tag -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
make
./main
test-linux-findpackage:
@@ -37,7 +37,7 @@ jobs:
tag=$(git rev-parse --abbrev-ref HEAD)
mkdir build
cd build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
sudo make -j install
cd ../..
cp -rv cpptrace/test/findpackage-integration .
@@ -61,7 +61,7 @@ jobs:
cp -rv cpptrace add_subdirectory-integration
mkdir add_subdirectory-integration/build
cd add_subdirectory-integration/build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
make
./main
@@ -81,7 +81,7 @@ jobs:
cp -rv cpptrace/test/fetchcontent-integration .
mkdir fetchcontent-integration/build
cd fetchcontent-integration/build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG=$tag -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG=$tag -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
make
./main
test-macos-findpackage:
@@ -98,7 +98,7 @@ jobs:
echo $tag
mkdir build
cd build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
sudo make -j install
cd ../..
cp -rv cpptrace/test/findpackage-integration .
@@ -122,7 +122,7 @@ jobs:
cp -rv cpptrace add_subdirectory-integration
mkdir add_subdirectory-integration/build
cd add_subdirectory-integration/build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
make
./main
@@ -142,7 +142,7 @@ jobs:
cp -Recurse cpptrace/test/fetchcontent-integration .
mkdir fetchcontent-integration/build
cd fetchcontent-integration/build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG="$tag" "-GUnix Makefiles" -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG="$tag" "-GUnix Makefiles" -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
make
.\main.exe
test-mingw-findpackage:
@@ -159,7 +159,7 @@ jobs:
echo $tag
mkdir build
cd build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}} "-GUnix Makefiles" -DCMAKE_INSTALL_PREFIX=C:/foo
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}} "-GUnix Makefiles" -DCMAKE_INSTALL_PREFIX=C:/foo -DCPPTRACE_WERROR_BUILD=On
make -j install
cd ../..
mv cpptrace/test/findpackage-integration .
@@ -183,7 +183,7 @@ jobs:
cp -Recurse cpptrace add_subdirectory-integration
mkdir add_subdirectory-integration/build
cd add_subdirectory-integration/build
- cmake .. -DCMAKE_BUILD_TYPE=Debug "-GUnix Makefiles" -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug "-GUnix Makefiles" -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
make
.\main.exe
test-windows-fetchcontent:
@@ -204,7 +204,7 @@ jobs:
cp -Recurse cpptrace/test/fetchcontent-integration .
mkdir fetchcontent-integration/build
cd fetchcontent-integration/build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG="$tag" -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG="$tag" -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
msbuild demo_project.sln
.\Debug\main.exe
test-windows-findpackage:
@@ -223,7 +223,7 @@ jobs:
echo $tag
mkdir build
cd build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCMAKE_INSTALL_PREFIX=C:/foo
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCMAKE_INSTALL_PREFIX=C:/foo -DCPPTRACE_WERROR_BUILD=On
msbuild cpptrace.sln
msbuild INSTALL.vcxproj
cd ../..
@@ -250,6 +250,6 @@ jobs:
cp -Recurse cpptrace add_subdirectory-integration
mkdir add_subdirectory-integration/build
cd add_subdirectory-integration/build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}}
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCPPTRACE_WERROR_BUILD=On
msbuild demo_project.sln
.\Debug\main.exe
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fca8e18..31ed78b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -237,23 +237,28 @@ target_include_directories(
$
)
-target_compile_options(
- ${target_name}
- PRIVATE
- $<$>:-Wall -Wextra -Werror=return-type -Wundef>
+set(
+ warning_options
+ $<$>:-Wall -Wextra -Werror=return-type -Wundef -Wpedantic>
$<$:-Wuseless-cast -Wmaybe-uninitialized>
$<$:/W4 /WX /permissive->
)
if(CPPTRACE_WERROR_BUILD)
- target_compile_options(
- ${target_name}
- PRIVATE
+ set(
+ warning_options
+ ${warning_options}
$<$>:-Werror>
$<$:/WX>
)
endif()
+target_compile_options(
+ ${target_name}
+ PRIVATE
+ ${warning_options}
+)
+
# ---- Generate Build Info Headers ----
if(build_type STREQUAL "STATIC")
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index bbb47e7..9ee7be0 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -5,6 +5,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
macro(add_test_dependencies exec_name)
target_compile_features(${exec_name} PRIVATE cxx_std_11)
target_link_libraries(${exec_name} PRIVATE ${target_name})
+ target_compile_options(${exec_name} PRIVATE ${warning_options})
# Clang has been fast to adopt dwarf 5, other tools (e.g. addr2line from binutils) have not
check_cxx_compiler_flag("-gdwarf-4" HAS_DWARF4)
if(HAS_DWARF4)
@@ -50,5 +51,6 @@ if(NOT CPPTRACE_IS_GH_ACTIONS)
add_executable(unittest unittest.cpp)
target_compile_features(unittest PRIVATE cxx_std_20)
target_link_libraries(unittest PRIVATE ${target_name} GTest::gtest_main GTest::gmock_main)
+ target_compile_options(unittest PRIVATE ${warning_options} -Wno-pedantic)
add_test(NAME unittest COMMAND unittest)
endif()
diff --git a/test/ctrace_demo.c b/test/ctrace_demo.c
index 4dc85df..3170766 100644
--- a/test/ctrace_demo.c
+++ b/test/ctrace_demo.c
@@ -23,14 +23,17 @@ void bar(int n) {
}
void foo(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
+ (void)a, (void)b, (void)c, (void)d, (void)e, (void)f, (void)g, (void)h, (void)i, (void)j;
bar(1);
}
void function_two(int a, float b) {
+ (void)a, (void)b;
foo(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
void function_one(int a) {
+ (void)a;
function_two(0, 0);
}
diff --git a/test/demo.cpp b/test/demo.cpp
index 88c54a9..46ba38d 100644
--- a/test/demo.cpp
+++ b/test/demo.cpp
@@ -20,7 +20,7 @@ void foo(int n) {
}
template
-void foo(int x, Args... args) {
+void foo(int, Args... args) {
foo(args...);
}
diff --git a/test/integration.cpp b/test/integration.cpp
index cdfc52d..c3ad4ed 100644
--- a/test/integration.cpp
+++ b/test/integration.cpp
@@ -29,11 +29,11 @@ void trace() {
// padding to avoid upsetting existing trace expected files
-void www(std::string&&, const std::string& str, std::vector&& foobar) {
+void www(std::string&&, const std::string&, std::vector&&) {
trace();
}
-void jjj(void(*const arr[5])(float)) {
+void jjj(void(*const[5])(float)) {
www(std::string{}, "", {});
}
@@ -101,7 +101,7 @@ void foo(int n) {
}
template
-void foo(int x, Args... args) {
+void foo(int, Args... args) {
x = 0;
foo(args...);
x = 0;