Add more GCC warning flags (#4524)

* 🔧 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
This commit is contained in:
Niels Lohmann 2024-12-01 16:13:48 +01:00 committed by GitHub
parent 1b9a9d1f21
commit a006a7a48b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 78 additions and 24 deletions

View File

@ -33,9 +33,11 @@ jobs:
ci_test_gcc: ci_test_gcc:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: ghcr.io/nlohmann/json-ci:v2.4.0 container: gcc:latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Get latest CMake and ninja
uses: lukka/get-cmake@v3.31.0
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@ -46,7 +48,13 @@ jobs:
container: ghcr.io/nlohmann/json-ci:v2.4.0 container: ghcr.io/nlohmann/json-ci:v2.4.0
strategy: strategy:
matrix: 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: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Run CMake - name: Run CMake
@ -54,6 +62,18 @@ jobs:
- name: Build - name: Build
run: cmake --build build --target ${{ matrix.target }} 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: ci_static_analysis_ubuntu:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -180,27 +200,16 @@ jobs:
- name: Build - name: Build
run: cmake --build build --target ci_test_compiler_default 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: ci_test_standards_gcc:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: ghcr.io/nlohmann/json-ci:v2.4.0 container: gcc:latest
strategy: strategy:
matrix: matrix:
standard: [11, 14, 17, 20, 23] standard: [11, 14, 17, 20, 23]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Get latest CMake and ninja
uses: lukka/get-cmake@v3.31.0
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build

View File

@ -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}") string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})") 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) 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}") 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})") message(STATUS "🔖 Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
@ -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}") string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CPPCHECK_TOOL_VERSION "${CPPCHECK_TOOL_VERSION}")
message(STATUS "🔖 Cppcheck ${CPPCHECK_TOOL_VERSION} (${CPPCHECK_TOOL})") 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) 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}") string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})") 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) 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}") string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCOV_TOOL_VERSION "${GCOV_TOOL_VERSION}")
message(STATUS "🔖 GCOV ${GCOV_TOOL_VERSION} (${GCOV_TOOL})") message(STATUS "🔖 GCOV ${GCOV_TOOL_VERSION} (${GCOV_TOOL})")
@ -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-padded We do not care about padding warnings.
# -Wno-covered-switch-default All switches list all cases and a default case. # -Wno-covered-switch-default All switches list all cases and a default case.
# -Wno-unsafe-buffer-usage Otherwise Doctest would not compile. # -Wno-unsafe-buffer-usage Otherwise Doctest would not compile.
# -Wreserved-identifier See https://github.com/onqtam/doctest/issues/536.
set(CLANG_CXXFLAGS set(CLANG_CXXFLAGS
-Werror -Werror
@ -108,15 +107,15 @@ set(CLANG_CXXFLAGS
-Wno-padded -Wno-padded
-Wno-covered-switch-default -Wno-covered-switch-default
-Wno-unsafe-buffer-usage -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: # Ignored GCC warnings:
# -Wno-abi-tag We do not care about ABI tags. # -Wno-abi-tag We do not care about ABI tags.
# -Wno-aggregate-return The library uses aggregate returns. # -Wno-aggregate-return The library uses aggregate returns.
# -Wno-long-long The library uses the long long type to interface with system functions. # -Wno-long-long The library uses the long long type to interface with system functions.
# -Wno-namespaces The library uses namespaces. # -Wno-namespaces The library uses namespaces.
# -Wno-nrvo Doctest triggers this warning.
# -Wno-padded We do not care about padding warnings. # -Wno-padded We do not care about padding warnings.
# -Wno-system-headers We do not care about warnings in system headers. # -Wno-system-headers We do not care about warnings in system headers.
# -Wno-templates The library uses templates. # -Wno-templates The library uses templates.
@ -135,28 +134,49 @@ set(GCC_CXXFLAGS
-Waggressive-loop-optimizations -Waggressive-loop-optimizations
-Waligned-new=all -Waligned-new=all
-Wall -Wall
-Walloc-size
-Walloc-zero -Walloc-zero
-Walloca -Walloca
-Wanalyzer-allocation-size
-Wanalyzer-deref-before-check
-Wanalyzer-double-fclose -Wanalyzer-double-fclose
-Wanalyzer-double-free -Wanalyzer-double-free
-Wanalyzer-exposure-through-output-file -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-file-leak
-Wanalyzer-free-of-non-heap -Wanalyzer-free-of-non-heap
-Wanalyzer-imprecise-fp-arithmetic
-Wanalyzer-infinite-loop
-Wanalyzer-infinite-recursion
-Wanalyzer-jump-through-null
-Wanalyzer-malloc-leak -Wanalyzer-malloc-leak
-Wanalyzer-mismatching-deallocation -Wanalyzer-mismatching-deallocation
-Wanalyzer-null-argument -Wanalyzer-null-argument
-Wanalyzer-null-dereference -Wanalyzer-null-dereference
-Wanalyzer-out-of-bounds
-Wanalyzer-overlapping-buffers
-Wanalyzer-possible-null-argument -Wanalyzer-possible-null-argument
-Wanalyzer-possible-null-dereference -Wanalyzer-possible-null-dereference
-Wanalyzer-putenv-of-auto-var
-Wanalyzer-shift-count-negative -Wanalyzer-shift-count-negative
-Wanalyzer-shift-count-overflow -Wanalyzer-shift-count-overflow
-Wanalyzer-stale-setjmp-buffer -Wanalyzer-stale-setjmp-buffer
-Wanalyzer-symbol-too-complex
-Wanalyzer-tainted-allocation-size -Wanalyzer-tainted-allocation-size
-Wanalyzer-tainted-array-index -Wanalyzer-tainted-array-index
-Wanalyzer-tainted-assertion
-Wanalyzer-tainted-divisor -Wanalyzer-tainted-divisor
-Wanalyzer-tainted-offset -Wanalyzer-tainted-offset
-Wanalyzer-tainted-size -Wanalyzer-tainted-size
-Wanalyzer-too-complex -Wanalyzer-too-complex
-Wanalyzer-undefined-behavior-strtok
-Wanalyzer-unsafe-call-within-signal-handler -Wanalyzer-unsafe-call-within-signal-handler
-Wanalyzer-use-after-free -Wanalyzer-use-after-free
-Wanalyzer-use-of-pointer-in-stale-stack-frame -Wanalyzer-use-of-pointer-in-stale-stack-frame
@ -189,13 +209,17 @@ set(GCC_CXXFLAGS
-Wc++20-compat -Wc++20-compat
-Wc++20-extensions -Wc++20-extensions
-Wc++23-extensions -Wc++23-extensions
-Wc++26-extensions
-Wc++2a-compat -Wc++2a-compat
-Wcalloc-transposed-args
-Wcannot-profile -Wcannot-profile
-Wcast-align -Wcast-align
-Wcast-align=strict -Wcast-align=strict
-Wcast-function-type -Wcast-function-type
-Wcast-qual -Wcast-qual
-Wcast-user-defined
-Wcatch-value=3 -Wcatch-value=3
-Wchanges-meaning
-Wchar-subscripts -Wchar-subscripts
-Wclass-conversion -Wclass-conversion
-Wclass-memaccess -Wclass-memaccess
@ -203,16 +227,19 @@ set(GCC_CXXFLAGS
-Wcomma-subscript -Wcomma-subscript
-Wcomment -Wcomment
-Wcomments -Wcomments
-Wcomplain-wrong-lang
-Wconditionally-supported -Wconditionally-supported
-Wconversion -Wconversion
-Wconversion-null -Wconversion-null
-Wcoverage-invalid-line-number -Wcoverage-invalid-line-number
-Wcoverage-mismatch -Wcoverage-mismatch
-Wcoverage-too-many-conditions
-Wcpp -Wcpp
-Wctad-maybe-unsupported -Wctad-maybe-unsupported
-Wctor-dtor-privacy -Wctor-dtor-privacy
-Wdangling-else -Wdangling-else
-Wdangling-pointer=2 -Wdangling-pointer=2
-Wdangling-reference
-Wdate-time -Wdate-time
-Wdelete-incomplete -Wdelete-incomplete
-Wdelete-non-virtual-dtor -Wdelete-non-virtual-dtor
@ -228,6 +255,7 @@ set(GCC_CXXFLAGS
-Wduplicated-branches -Wduplicated-branches
-Wduplicated-cond -Wduplicated-cond
-Weffc++ -Weffc++
-Welaborated-enum-base
-Wempty-body -Wempty-body
-Wendif-labels -Wendif-labels
-Wenum-compare -Wenum-compare
@ -236,8 +264,15 @@ set(GCC_CXXFLAGS
-Wexpansion-to-defined -Wexpansion-to-defined
-Wextra -Wextra
-Wextra-semi -Wextra-semi
-Wflex-array-member-not-at-end
-Wfloat-conversion -Wfloat-conversion
-Wfloat-equal -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-diag
-Wformat-overflow=2 -Wformat-overflow=2
-Wformat-signedness -Wformat-signedness
@ -245,6 +280,8 @@ set(GCC_CXXFLAGS
-Wformat=2 -Wformat=2
-Wframe-address -Wframe-address
-Wfree-nonheap-object -Wfree-nonheap-object
-Wglobal-module
-Whardened
-Whsa -Whsa
-Wif-not-aligned -Wif-not-aligned
-Wignored-attributes -Wignored-attributes
@ -259,10 +296,12 @@ set(GCC_CXXFLAGS
-Wint-in-bool-context -Wint-in-bool-context
-Wint-to-pointer-cast -Wint-to-pointer-cast
-Winterference-size -Winterference-size
-Winvalid-constexpr
-Winvalid-imported-macros -Winvalid-imported-macros
-Winvalid-memory-model -Winvalid-memory-model
-Winvalid-offsetof -Winvalid-offsetof
-Winvalid-pch -Winvalid-pch
-Winvalid-utf8
-Wliteral-suffix -Wliteral-suffix
-Wlogical-not-parentheses -Wlogical-not-parentheses
-Wlogical-op -Wlogical-op
@ -296,14 +335,16 @@ set(GCC_CXXFLAGS
-Wnonnull -Wnonnull
-Wnonnull-compare -Wnonnull-compare
-Wnormalized=nfkc -Wnormalized=nfkc
-Wno-nrvo
-Wnull-dereference -Wnull-dereference
-Wodr -Wodr
-Wold-style-cast -Wold-style-cast
-Wopenacc-parallelism -Wopenacc-parallelism
-Wopenmp
-Wopenmp-simd -Wopenmp-simd
-Woverflow -Woverflow
-Woverlength-strings -Woverlength-strings
-Woverloaded-virtual -Woverloaded-virtual=2
-Wpacked -Wpacked
-Wpacked-bitfield-compat -Wpacked-bitfield-compat
-Wpacked-not-aligned -Wpacked-not-aligned
@ -328,6 +369,7 @@ set(GCC_CXXFLAGS
-Wreturn-local-addr -Wreturn-local-addr
-Wreturn-type -Wreturn-type
-Wscalar-storage-order -Wscalar-storage-order
-Wself-move
-Wsequence-point -Wsequence-point
-Wshadow=compatible-local -Wshadow=compatible-local
-Wshadow=global -Wshadow=global
@ -347,7 +389,7 @@ set(GCC_CXXFLAGS
-Wstack-protector -Wstack-protector
-Wstrict-aliasing=3 -Wstrict-aliasing=3
-Wstrict-null-sentinel -Wstrict-null-sentinel
-Wno-strict-overflow -Wstrict-overflow
-Wstring-compare -Wstring-compare
-Wstringop-overflow=4 -Wstringop-overflow=4
-Wstringop-overread -Wstringop-overread
@ -359,6 +401,7 @@ set(GCC_CXXFLAGS
-Wsuggest-attribute=malloc -Wsuggest-attribute=malloc
-Wsuggest-attribute=noreturn -Wsuggest-attribute=noreturn
-Wsuggest-attribute=pure -Wsuggest-attribute=pure
-Wsuggest-attribute=returns_nonnull
-Wsuggest-final-methods -Wsuggest-final-methods
-Wsuggest-final-types -Wsuggest-final-types
-Wsuggest-override -Wsuggest-override
@ -380,6 +423,7 @@ set(GCC_CXXFLAGS
-Wtsan -Wtsan
-Wtype-limits -Wtype-limits
-Wundef -Wundef
-Wunicode
-Wuninitialized -Wuninitialized
-Wunknown-pragmas -Wunknown-pragmas
-Wunreachable-code -Wunreachable-code
@ -409,6 +453,7 @@ set(GCC_CXXFLAGS
-Wvolatile -Wvolatile
-Wvolatile-register-var -Wvolatile-register-var
-Wwrite-strings -Wwrite-strings
-Wxor-used-as-pow
-Wzero-as-null-pointer-constant -Wzero-as-null-pointer-constant
-Wzero-length-bounds -Wzero-length-bounds
) )