Skip to content

Commit

Permalink
Add more GCC warning flags (#4524)
Browse files Browse the repository at this point in the history
* 🔧 add more GCC warning flags

* 👷 use GCC image for GCC test

* 👷 use GCC image for GCC test

* 👷 use GCC image for GCC test

* 👷 use GCC image for GCC test

* 👷 use GCC image for GCC test

* 👷 use GCC image for GCC test

* 👷 use GCC image for GCC test

* 👷 use GCC image for GCC test

* 🔧 adjust flags

* 👷 adjust jobs

* 👷 adjust jobs
  • Loading branch information
nlohmann authored Dec 1, 2024
1 parent 1b9a9d1 commit a006a7a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 24 deletions.
41 changes: 25 additions & 16 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ jobs:

ci_test_gcc:
runs-on: ubuntu-latest
container: ghcr.io/nlohmann/json-ci:v2.4.0
container: gcc:latest
steps:
- uses: actions/checkout@v4
- name: Get latest CMake and ninja
uses: lukka/get-cmake@v3.31.0
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
Expand All @@ -46,14 +48,32 @@ jobs:
container: ghcr.io/nlohmann/json-ci:v2.4.0
strategy:
matrix:
target: [ci_cppcheck, ci_test_valgrind, ci_test_amalgamation, ci_test_single_header, ci_single_binaries, ci_infer]
target: [
ci_cppcheck, # needs cppcheck
ci_test_valgrind, # needs Valgrind
ci_test_amalgamation, # needs AStyle
ci_infer, # needs Infer
ci_single_binaries # needs iwyu
]
steps:
- uses: actions/checkout@v4
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
run: cmake --build build --target ${{ matrix.target }}

ci_test_single_header:
runs-on: ubuntu-latest
container: gcc:latest
steps:
- uses: actions/checkout@v4
- name: Get latest CMake and ninja
uses: lukka/get-cmake@v3.31.0
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
run: cmake --build build --target ci_test_single_header

ci_static_analysis_ubuntu:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -180,27 +200,16 @@ jobs:
- name: Build
run: cmake --build build --target ci_test_compiler_default

ci_test_compilers:
runs-on: ubuntu-latest
container: ghcr.io/nlohmann/json-ci:v2.4.0
strategy:
matrix:
compiler: [g++-4.8]
steps:
- uses: actions/checkout@v4
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
run: cmake --build build --target ci_test_compiler_${{ matrix.compiler }}

ci_test_standards_gcc:
runs-on: ubuntu-latest
container: ghcr.io/nlohmann/json-ci:v2.4.0
container: gcc:latest
strategy:
matrix:
standard: [11, 14, 17, 20, 23]
steps:
- uses: actions/checkout@v4
- name: Get latest CMake and ninja
uses: lukka/get-cmake@v3.31.0
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
Expand Down
61 changes: 53 additions & 8 deletions cmake/ci.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSI
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")

find_program(CLANG_TIDY_TOOL NAMES clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
find_program(CLANG_TIDY_TOOL NAMES clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION)
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
message(STATUS "🔖 Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
Expand All @@ -30,12 +30,12 @@ execute_process(COMMAND ${CPPCHECK_TOOL} --version OUTPUT_VARIABLE CPPCHECK_TOOL
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CPPCHECK_TOOL_VERSION "${CPPCHECK_TOOL_VERSION}")
message(STATUS "🔖 Cppcheck ${CPPCHECK_TOOL_VERSION} (${CPPCHECK_TOOL})")

find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++-13 g++-12 g++-11 g++-10)
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++ g++-15 g++-14 g++-13 g++-12 g++-11 g++-10)
execute_process(COMMAND ${GCC_TOOL} --version OUTPUT_VARIABLE GCC_TOOL_VERSION ERROR_VARIABLE GCC_TOOL_VERSION)
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")

find_program(GCOV_TOOL NAMES gcov-HEAD gcov-11 gcov-10 gcov)
find_program(GCOV_TOOL NAMES gcov-HEAD gcov-15 gcov-14 gcov-13 gcov-12 gcov-11 gcov-10 gcov)
execute_process(COMMAND ${GCOV_TOOL} --version OUTPUT_VARIABLE GCOV_TOOL_VERSION ERROR_VARIABLE GCOV_TOOL_VERSION)
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCOV_TOOL_VERSION "${GCOV_TOOL_VERSION}")
message(STATUS "🔖 GCOV ${GCOV_TOOL_VERSION} (${GCOV_TOOL})")
Expand Down Expand Up @@ -96,7 +96,6 @@ file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp)
# -Wno-padded We do not care about padding warnings.
# -Wno-covered-switch-default All switches list all cases and a default case.
# -Wno-unsafe-buffer-usage Otherwise Doctest would not compile.
# -Wreserved-identifier See https://github.com/onqtam/doctest/issues/536.

set(CLANG_CXXFLAGS
-Werror
Expand All @@ -108,15 +107,15 @@ set(CLANG_CXXFLAGS
-Wno-padded
-Wno-covered-switch-default
-Wno-unsafe-buffer-usage
-Wno-reserved-identifier
)

# Warning flags determined for GCC 13.0 (experimental) with https://github.com/nlohmann/gcc_flags:
# Warning flags determined for GCC 14.2.0 with https://github.com/nlohmann/gcc_flags:
# Ignored GCC warnings:
# -Wno-abi-tag We do not care about ABI tags.
# -Wno-aggregate-return The library uses aggregate returns.
# -Wno-long-long The library uses the long long type to interface with system functions.
# -Wno-namespaces The library uses namespaces.
# -Wno-nrvo Doctest triggers this warning.
# -Wno-padded We do not care about padding warnings.
# -Wno-system-headers We do not care about warnings in system headers.
# -Wno-templates The library uses templates.
Expand All @@ -135,28 +134,49 @@ set(GCC_CXXFLAGS
-Waggressive-loop-optimizations
-Waligned-new=all
-Wall
-Walloc-size
-Walloc-zero
-Walloca
-Wanalyzer-allocation-size
-Wanalyzer-deref-before-check
-Wanalyzer-double-fclose
-Wanalyzer-double-free
-Wanalyzer-exposure-through-output-file
-Wanalyzer-exposure-through-uninit-copy
-Wanalyzer-fd-access-mode-mismatch
-Wanalyzer-fd-double-close
-Wanalyzer-fd-leak
-Wanalyzer-fd-phase-mismatch
-Wanalyzer-fd-type-mismatch
-Wanalyzer-fd-use-after-close
-Wanalyzer-fd-use-without-check
-Wanalyzer-file-leak
-Wanalyzer-free-of-non-heap
-Wanalyzer-imprecise-fp-arithmetic
-Wanalyzer-infinite-loop
-Wanalyzer-infinite-recursion
-Wanalyzer-jump-through-null
-Wanalyzer-malloc-leak
-Wanalyzer-mismatching-deallocation
-Wanalyzer-null-argument
-Wanalyzer-null-dereference
-Wanalyzer-out-of-bounds
-Wanalyzer-overlapping-buffers
-Wanalyzer-possible-null-argument
-Wanalyzer-possible-null-dereference
-Wanalyzer-putenv-of-auto-var
-Wanalyzer-shift-count-negative
-Wanalyzer-shift-count-overflow
-Wanalyzer-stale-setjmp-buffer
-Wanalyzer-symbol-too-complex
-Wanalyzer-tainted-allocation-size
-Wanalyzer-tainted-array-index
-Wanalyzer-tainted-assertion
-Wanalyzer-tainted-divisor
-Wanalyzer-tainted-offset
-Wanalyzer-tainted-size
-Wanalyzer-too-complex
-Wanalyzer-undefined-behavior-strtok
-Wanalyzer-unsafe-call-within-signal-handler
-Wanalyzer-use-after-free
-Wanalyzer-use-of-pointer-in-stale-stack-frame
Expand Down Expand Up @@ -189,30 +209,37 @@ set(GCC_CXXFLAGS
-Wc++20-compat
-Wc++20-extensions
-Wc++23-extensions
-Wc++26-extensions
-Wc++2a-compat
-Wcalloc-transposed-args
-Wcannot-profile
-Wcast-align
-Wcast-align=strict
-Wcast-function-type
-Wcast-qual
-Wcast-user-defined
-Wcatch-value=3
-Wchanges-meaning
-Wchar-subscripts
-Wclass-conversion
-Wclass-memaccess
-Wclobbered
-Wcomma-subscript
-Wcomment
-Wcomments
-Wcomplain-wrong-lang
-Wconditionally-supported
-Wconversion
-Wconversion-null
-Wcoverage-invalid-line-number
-Wcoverage-mismatch
-Wcoverage-too-many-conditions
-Wcpp
-Wctad-maybe-unsupported
-Wctor-dtor-privacy
-Wdangling-else
-Wdangling-pointer=2
-Wdangling-reference
-Wdate-time
-Wdelete-incomplete
-Wdelete-non-virtual-dtor
Expand All @@ -228,6 +255,7 @@ set(GCC_CXXFLAGS
-Wduplicated-branches
-Wduplicated-cond
-Weffc++
-Welaborated-enum-base
-Wempty-body
-Wendif-labels
-Wenum-compare
Expand All @@ -236,15 +264,24 @@ set(GCC_CXXFLAGS
-Wexpansion-to-defined
-Wextra
-Wextra-semi
-Wflex-array-member-not-at-end
-Wfloat-conversion
-Wfloat-equal
-Wformat -Wformat-contains-nul
-Wformat -Wformat-extra-args
-Wformat -Wformat-nonliteral
-Wformat -Wformat-security
-Wformat -Wformat-y2k
-Wformat -Wformat-zero-length
-Wformat-diag
-Wformat-overflow=2
-Wformat-signedness
-Wformat-truncation=2
-Wformat=2
-Wframe-address
-Wfree-nonheap-object
-Wglobal-module
-Whardened
-Whsa
-Wif-not-aligned
-Wignored-attributes
Expand All @@ -259,10 +296,12 @@ set(GCC_CXXFLAGS
-Wint-in-bool-context
-Wint-to-pointer-cast
-Winterference-size
-Winvalid-constexpr
-Winvalid-imported-macros
-Winvalid-memory-model
-Winvalid-offsetof
-Winvalid-pch
-Winvalid-utf8
-Wliteral-suffix
-Wlogical-not-parentheses
-Wlogical-op
Expand Down Expand Up @@ -296,14 +335,16 @@ set(GCC_CXXFLAGS
-Wnonnull
-Wnonnull-compare
-Wnormalized=nfkc
-Wno-nrvo
-Wnull-dereference
-Wodr
-Wold-style-cast
-Wopenacc-parallelism
-Wopenmp
-Wopenmp-simd
-Woverflow
-Woverlength-strings
-Woverloaded-virtual
-Woverloaded-virtual=2
-Wpacked
-Wpacked-bitfield-compat
-Wpacked-not-aligned
Expand All @@ -328,6 +369,7 @@ set(GCC_CXXFLAGS
-Wreturn-local-addr
-Wreturn-type
-Wscalar-storage-order
-Wself-move
-Wsequence-point
-Wshadow=compatible-local
-Wshadow=global
Expand All @@ -347,7 +389,7 @@ set(GCC_CXXFLAGS
-Wstack-protector
-Wstrict-aliasing=3
-Wstrict-null-sentinel
-Wno-strict-overflow
-Wstrict-overflow
-Wstring-compare
-Wstringop-overflow=4
-Wstringop-overread
Expand All @@ -359,6 +401,7 @@ set(GCC_CXXFLAGS
-Wsuggest-attribute=malloc
-Wsuggest-attribute=noreturn
-Wsuggest-attribute=pure
-Wsuggest-attribute=returns_nonnull
-Wsuggest-final-methods
-Wsuggest-final-types
-Wsuggest-override
Expand All @@ -380,6 +423,7 @@ set(GCC_CXXFLAGS
-Wtsan
-Wtype-limits
-Wundef
-Wunicode
-Wuninitialized
-Wunknown-pragmas
-Wunreachable-code
Expand Down Expand Up @@ -409,6 +453,7 @@ set(GCC_CXXFLAGS
-Wvolatile
-Wvolatile-register-var
-Wwrite-strings
-Wxor-used-as-pow
-Wzero-as-null-pointer-constant
-Wzero-length-bounds
)
Expand Down

0 comments on commit a006a7a

Please sign in to comment.