From 14d83586079a6d160c7564b06b854e8156b4192f Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 22 Nov 2024 17:25:08 +0100 Subject: [PATCH 1/6] fail builds in CI on compiler warnings --- .github/workflows/CI-unixish.yml | 14 ++++++++------ .github/workflows/CI-windows.yml | 6 ++++-- .github/workflows/clang-tidy.yml | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index ff7c3f65..c0daf000 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -41,9 +41,11 @@ jobs: python3 -m pip config set global.break-system-packages true python3 -m pip install pytest + # TODO: bail out on warnings - name: make simplecpp run: make -j$(nproc) + # TODO: bail out on warnings - name: make test run: make -j$(nproc) test @@ -57,7 +59,7 @@ jobs: - name: Run CMake run: | - cmake -S . -B cmake.output + cmake -S . -B cmake.output -DCMAKE_COMPILE_WARNING_AS_ERROR=On - name: CMake simplecpp run: | @@ -80,19 +82,19 @@ jobs: if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'g++' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-g3 -D_GLIBCXX_DEBUG" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -g3 -D_GLIBCXX_DEBUG" - name: Run with libc++ hardening mode if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'clang++' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-stdlib=libc++ -g3 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" LDFLAGS="-lc++" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -stdlib=libc++ -g3 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" LDFLAGS="-lc++" - name: Run AddressSanitizer if: matrix.os == 'ubuntu-24.04' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-O2 -g3 -fsanitize=address" LDFLAGS="-fsanitize=address" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -O2 -g3 -fsanitize=address" LDFLAGS="-fsanitize=address" env: ASAN_OPTIONS: detect_stack_use_after_return=1 @@ -100,7 +102,7 @@ jobs: if: matrix.os == 'ubuntu-24.04' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-O2 -g3 -fsanitize=undefined -fno-sanitize=signed-integer-overflow" LDFLAGS="-fsanitize=undefined -fno-sanitize=signed-integer-overflow" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -O2 -g3 -fsanitize=undefined -fno-sanitize=signed-integer-overflow" LDFLAGS="-fsanitize=undefined -fno-sanitize=signed-integer-overflow" env: UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1:report_error_type=1 @@ -109,4 +111,4 @@ jobs: if: false && matrix.os == 'ubuntu-24.04' && matrix.compiler == 'clang++' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-O2 -g3 -stdlib=libc++ -fsanitize=memory" LDFLAGS="-lc++ -fsanitize=memory" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -O2 -g3 -stdlib=libc++ -fsanitize=memory" LDFLAGS="-lc++ -fsanitize=memory" diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml index 971f3827..61c0cf5b 100644 --- a/.github/workflows/CI-windows.yml +++ b/.github/workflows/CI-windows.yml @@ -40,12 +40,14 @@ jobs: - name: Run CMake run: | - cmake -G "Visual Studio 17 2022" -A x64 . || exit /b !errorlevel! + cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_COMPILE_WARNING_AS_ERROR=On . || exit /b !errorlevel! - name: Build run: | msbuild -m simplecpp.sln /p:Configuration=${{ matrix.config }} /p:Platform=x64 || exit /b !errorlevel! - + env: + _CL_: /WX + - name: Test run: | .\${{ matrix.config }}\testrunner.exe || exit /b !errorlevel! diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index a2f7b6dc..41d2ee6f 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -30,7 +30,7 @@ jobs: - name: Prepare CMake run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_EXPORT_COMPILE_COMMANDS=ON env: CXX: clang-20 From f81b3170d581bb467ed8b28e3ec710f8283b7296 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 22 Nov 2024 17:29:24 +0100 Subject: [PATCH 2/6] CI-unixish.yml: fixed missing `nproc` on `macos-*` --- .github/workflows/CI-unixish.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index c0daf000..354a44d5 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -31,6 +31,12 @@ jobs: sudo apt-get update sudo apt-get install libc++-18-dev + # coreutils contains "nproc" + - name: Install missing software on macos + if: contains(matrix.os, 'macos') + run: | + brew install coreutils + - name: Install missing software on macos if: contains(matrix.os, 'macos') run: | From a1b01571da62957fba303e634f2f13042ade9632 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 22 Nov 2024 22:38:50 +0100 Subject: [PATCH 3/6] disabled `-Wshadow` GCC warnings in CMake for now --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ab0166e..a7e61613 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") add_compile_options(-Wsuggest-attribute=noreturn) add_compile_options_safe(-Wuseless-cast) + + add_compile_options(-Wno-shadow) # TODO: fix these elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") add_compile_definitions(_CRT_SECURE_NO_WARNINGS) elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") From 6d1a765351149058a1c1095b776e4692117432ef Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 22 Nov 2024 22:43:04 +0100 Subject: [PATCH 4/6] suppress `-Wc++11-long-long` on macOS --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7e61613..140177bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,10 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # TODO: fix these? add_compile_options(-Wno-padded -Wno-sign-conversion -Wno-implicit-int-conversion -Wno-shorten-64-to-32 -Wno-shadow-field-in-constructor) + if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + add_compile_options(-Wno-c++11-long-long) + endif() + if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14) # TODO: verify this regression still exists in clang-15 if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") From bfa5fdbd61bb4dcf4c80dbd0bf9b1e52db8d3681 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 22 Nov 2024 22:44:49 +0100 Subject: [PATCH 5/6] s --- .github/workflows/CI-unixish.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 354a44d5..8315c81f 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -88,19 +88,19 @@ jobs: if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'g++' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-Werror -g3 -D_GLIBCXX_DEBUG" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -Wno-multichar -g3 -D_GLIBCXX_DEBUG" - name: Run with libc++ hardening mode if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'clang++' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-Werror -stdlib=libc++ -g3 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" LDFLAGS="-lc++" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -Wno-multichar -stdlib=libc++ -g3 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" LDFLAGS="-lc++" - name: Run AddressSanitizer if: matrix.os == 'ubuntu-24.04' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-Werror -O2 -g3 -fsanitize=address" LDFLAGS="-fsanitize=address" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -Wno-multichar -O2 -g3 -fsanitize=address" LDFLAGS="-fsanitize=address" env: ASAN_OPTIONS: detect_stack_use_after_return=1 @@ -108,7 +108,7 @@ jobs: if: matrix.os == 'ubuntu-24.04' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-Werror -O2 -g3 -fsanitize=undefined -fno-sanitize=signed-integer-overflow" LDFLAGS="-fsanitize=undefined -fno-sanitize=signed-integer-overflow" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -Wno-multichar -O2 -g3 -fsanitize=undefined -fno-sanitize=signed-integer-overflow" LDFLAGS="-fsanitize=undefined -fno-sanitize=signed-integer-overflow" env: UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1:report_error_type=1 @@ -117,4 +117,4 @@ jobs: if: false && matrix.os == 'ubuntu-24.04' && matrix.compiler == 'clang++' run: | make clean - make -j$(nproc) test selfcheck CXXFLAGS="-Werror -O2 -g3 -stdlib=libc++ -fsanitize=memory" LDFLAGS="-lc++ -fsanitize=memory" + make -j$(nproc) test selfcheck CXXFLAGS="-Werror -Wno-multichar -O2 -g3 -stdlib=libc++ -fsanitize=memory" LDFLAGS="-lc++ -fsanitize=memory" From 88e3c16a50b49e11d6f83cc0b5ec65d992e106b6 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Aug 2025 14:50:02 +0200 Subject: [PATCH 6/6] simplecpp.cpp: fixed Visual Studio C4800 compiler warnings these only show up in Appveyor --- simplecpp.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index 5093b4b7..29de99dc 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -745,7 +745,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, // number or name if (isNameChar(ch)) { - const bool num = std::isdigit(ch); + const bool num = !!std::isdigit(ch); while (stream.good() && isNameChar(ch)) { currentToken += ch; ch = stream.readChar(); @@ -886,7 +886,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, } if (prefix.empty()) - push_back(new Token(s, location, std::isspace(stream.peekChar()))); // push string without newlines + push_back(new Token(s, location, !!std::isspace(stream.peekChar()))); // push string without newlines else back()->setstr(prefix + s); @@ -916,7 +916,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, } } - push_back(new Token(currentToken, location, std::isspace(stream.peekChar()))); + push_back(new Token(currentToken, location, !!std::isspace(stream.peekChar()))); if (multiline) location.col += currentToken.size();