Skip to content

Commit a006a7a

Browse files
authored
Add more GCC warning flags (nlohmann#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
1 parent 1b9a9d1 commit a006a7a

File tree

2 files changed

+78
-24
lines changed

2 files changed

+78
-24
lines changed

.github/workflows/ubuntu.yml

+25-16
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ jobs:
3333

3434
ci_test_gcc:
3535
runs-on: ubuntu-latest
36-
container: ghcr.io/nlohmann/json-ci:v2.4.0
36+
container: gcc:latest
3737
steps:
3838
- uses: actions/checkout@v4
39+
- name: Get latest CMake and ninja
40+
uses: lukka/[email protected]
3941
- name: Run CMake
4042
run: cmake -S . -B build -DJSON_CI=On
4143
- name: Build
@@ -46,14 +48,32 @@ jobs:
4648
container: ghcr.io/nlohmann/json-ci:v2.4.0
4749
strategy:
4850
matrix:
49-
target: [ci_cppcheck, ci_test_valgrind, ci_test_amalgamation, ci_test_single_header, ci_single_binaries, ci_infer]
51+
target: [
52+
ci_cppcheck, # needs cppcheck
53+
ci_test_valgrind, # needs Valgrind
54+
ci_test_amalgamation, # needs AStyle
55+
ci_infer, # needs Infer
56+
ci_single_binaries # needs iwyu
57+
]
5058
steps:
5159
- uses: actions/checkout@v4
5260
- name: Run CMake
5361
run: cmake -S . -B build -DJSON_CI=On
5462
- name: Build
5563
run: cmake --build build --target ${{ matrix.target }}
5664

65+
ci_test_single_header:
66+
runs-on: ubuntu-latest
67+
container: gcc:latest
68+
steps:
69+
- uses: actions/checkout@v4
70+
- name: Get latest CMake and ninja
71+
uses: lukka/[email protected]
72+
- name: Run CMake
73+
run: cmake -S . -B build -DJSON_CI=On
74+
- name: Build
75+
run: cmake --build build --target ci_test_single_header
76+
5777
ci_static_analysis_ubuntu:
5878
runs-on: ubuntu-latest
5979
strategy:
@@ -180,27 +200,16 @@ jobs:
180200
- name: Build
181201
run: cmake --build build --target ci_test_compiler_default
182202

183-
ci_test_compilers:
184-
runs-on: ubuntu-latest
185-
container: ghcr.io/nlohmann/json-ci:v2.4.0
186-
strategy:
187-
matrix:
188-
compiler: [g++-4.8]
189-
steps:
190-
- uses: actions/checkout@v4
191-
- name: Run CMake
192-
run: cmake -S . -B build -DJSON_CI=On
193-
- name: Build
194-
run: cmake --build build --target ci_test_compiler_${{ matrix.compiler }}
195-
196203
ci_test_standards_gcc:
197204
runs-on: ubuntu-latest
198-
container: ghcr.io/nlohmann/json-ci:v2.4.0
205+
container: gcc:latest
199206
strategy:
200207
matrix:
201208
standard: [11, 14, 17, 20, 23]
202209
steps:
203210
- uses: actions/checkout@v4
211+
- name: Get latest CMake and ninja
212+
uses: lukka/[email protected]
204213
- name: Run CMake
205214
run: cmake -S . -B build -DJSON_CI=On
206215
- name: Build

cmake/ci.cmake

+53-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSI
1818
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
1919
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
2020

21-
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)
21+
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)
2222
execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION)
2323
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
2424
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
3030
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CPPCHECK_TOOL_VERSION "${CPPCHECK_TOOL_VERSION}")
3131
message(STATUS "🔖 Cppcheck ${CPPCHECK_TOOL_VERSION} (${CPPCHECK_TOOL})")
3232

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

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

101100
set(CLANG_CXXFLAGS
102101
-Werror
@@ -108,15 +107,15 @@ set(CLANG_CXXFLAGS
108107
-Wno-padded
109108
-Wno-covered-switch-default
110109
-Wno-unsafe-buffer-usage
111-
-Wno-reserved-identifier
112110
)
113111

114-
# Warning flags determined for GCC 13.0 (experimental) with https://github.com/nlohmann/gcc_flags:
112+
# Warning flags determined for GCC 14.2.0 with https://github.com/nlohmann/gcc_flags:
115113
# Ignored GCC warnings:
116114
# -Wno-abi-tag We do not care about ABI tags.
117115
# -Wno-aggregate-return The library uses aggregate returns.
118116
# -Wno-long-long The library uses the long long type to interface with system functions.
119117
# -Wno-namespaces The library uses namespaces.
118+
# -Wno-nrvo Doctest triggers this warning.
120119
# -Wno-padded We do not care about padding warnings.
121120
# -Wno-system-headers We do not care about warnings in system headers.
122121
# -Wno-templates The library uses templates.
@@ -135,28 +134,49 @@ set(GCC_CXXFLAGS
135134
-Waggressive-loop-optimizations
136135
-Waligned-new=all
137136
-Wall
137+
-Walloc-size
138138
-Walloc-zero
139139
-Walloca
140+
-Wanalyzer-allocation-size
141+
-Wanalyzer-deref-before-check
140142
-Wanalyzer-double-fclose
141143
-Wanalyzer-double-free
142144
-Wanalyzer-exposure-through-output-file
145+
-Wanalyzer-exposure-through-uninit-copy
146+
-Wanalyzer-fd-access-mode-mismatch
147+
-Wanalyzer-fd-double-close
148+
-Wanalyzer-fd-leak
149+
-Wanalyzer-fd-phase-mismatch
150+
-Wanalyzer-fd-type-mismatch
151+
-Wanalyzer-fd-use-after-close
152+
-Wanalyzer-fd-use-without-check
143153
-Wanalyzer-file-leak
144154
-Wanalyzer-free-of-non-heap
155+
-Wanalyzer-imprecise-fp-arithmetic
156+
-Wanalyzer-infinite-loop
157+
-Wanalyzer-infinite-recursion
158+
-Wanalyzer-jump-through-null
145159
-Wanalyzer-malloc-leak
146160
-Wanalyzer-mismatching-deallocation
147161
-Wanalyzer-null-argument
148162
-Wanalyzer-null-dereference
163+
-Wanalyzer-out-of-bounds
164+
-Wanalyzer-overlapping-buffers
149165
-Wanalyzer-possible-null-argument
150166
-Wanalyzer-possible-null-dereference
167+
-Wanalyzer-putenv-of-auto-var
151168
-Wanalyzer-shift-count-negative
152169
-Wanalyzer-shift-count-overflow
153170
-Wanalyzer-stale-setjmp-buffer
171+
-Wanalyzer-symbol-too-complex
154172
-Wanalyzer-tainted-allocation-size
155173
-Wanalyzer-tainted-array-index
174+
-Wanalyzer-tainted-assertion
156175
-Wanalyzer-tainted-divisor
157176
-Wanalyzer-tainted-offset
158177
-Wanalyzer-tainted-size
159178
-Wanalyzer-too-complex
179+
-Wanalyzer-undefined-behavior-strtok
160180
-Wanalyzer-unsafe-call-within-signal-handler
161181
-Wanalyzer-use-after-free
162182
-Wanalyzer-use-of-pointer-in-stale-stack-frame
@@ -189,30 +209,37 @@ set(GCC_CXXFLAGS
189209
-Wc++20-compat
190210
-Wc++20-extensions
191211
-Wc++23-extensions
212+
-Wc++26-extensions
192213
-Wc++2a-compat
214+
-Wcalloc-transposed-args
193215
-Wcannot-profile
194216
-Wcast-align
195217
-Wcast-align=strict
196218
-Wcast-function-type
197219
-Wcast-qual
220+
-Wcast-user-defined
198221
-Wcatch-value=3
222+
-Wchanges-meaning
199223
-Wchar-subscripts
200224
-Wclass-conversion
201225
-Wclass-memaccess
202226
-Wclobbered
203227
-Wcomma-subscript
204228
-Wcomment
205229
-Wcomments
230+
-Wcomplain-wrong-lang
206231
-Wconditionally-supported
207232
-Wconversion
208233
-Wconversion-null
209234
-Wcoverage-invalid-line-number
210235
-Wcoverage-mismatch
236+
-Wcoverage-too-many-conditions
211237
-Wcpp
212238
-Wctad-maybe-unsupported
213239
-Wctor-dtor-privacy
214240
-Wdangling-else
215241
-Wdangling-pointer=2
242+
-Wdangling-reference
216243
-Wdate-time
217244
-Wdelete-incomplete
218245
-Wdelete-non-virtual-dtor
@@ -228,6 +255,7 @@ set(GCC_CXXFLAGS
228255
-Wduplicated-branches
229256
-Wduplicated-cond
230257
-Weffc++
258+
-Welaborated-enum-base
231259
-Wempty-body
232260
-Wendif-labels
233261
-Wenum-compare
@@ -236,15 +264,24 @@ set(GCC_CXXFLAGS
236264
-Wexpansion-to-defined
237265
-Wextra
238266
-Wextra-semi
267+
-Wflex-array-member-not-at-end
239268
-Wfloat-conversion
240269
-Wfloat-equal
270+
-Wformat -Wformat-contains-nul
271+
-Wformat -Wformat-extra-args
272+
-Wformat -Wformat-nonliteral
273+
-Wformat -Wformat-security
274+
-Wformat -Wformat-y2k
275+
-Wformat -Wformat-zero-length
241276
-Wformat-diag
242277
-Wformat-overflow=2
243278
-Wformat-signedness
244279
-Wformat-truncation=2
245280
-Wformat=2
246281
-Wframe-address
247282
-Wfree-nonheap-object
283+
-Wglobal-module
284+
-Whardened
248285
-Whsa
249286
-Wif-not-aligned
250287
-Wignored-attributes
@@ -259,10 +296,12 @@ set(GCC_CXXFLAGS
259296
-Wint-in-bool-context
260297
-Wint-to-pointer-cast
261298
-Winterference-size
299+
-Winvalid-constexpr
262300
-Winvalid-imported-macros
263301
-Winvalid-memory-model
264302
-Winvalid-offsetof
265303
-Winvalid-pch
304+
-Winvalid-utf8
266305
-Wliteral-suffix
267306
-Wlogical-not-parentheses
268307
-Wlogical-op
@@ -296,14 +335,16 @@ set(GCC_CXXFLAGS
296335
-Wnonnull
297336
-Wnonnull-compare
298337
-Wnormalized=nfkc
338+
-Wno-nrvo
299339
-Wnull-dereference
300340
-Wodr
301341
-Wold-style-cast
302342
-Wopenacc-parallelism
343+
-Wopenmp
303344
-Wopenmp-simd
304345
-Woverflow
305346
-Woverlength-strings
306-
-Woverloaded-virtual
347+
-Woverloaded-virtual=2
307348
-Wpacked
308349
-Wpacked-bitfield-compat
309350
-Wpacked-not-aligned
@@ -328,6 +369,7 @@ set(GCC_CXXFLAGS
328369
-Wreturn-local-addr
329370
-Wreturn-type
330371
-Wscalar-storage-order
372+
-Wself-move
331373
-Wsequence-point
332374
-Wshadow=compatible-local
333375
-Wshadow=global
@@ -347,7 +389,7 @@ set(GCC_CXXFLAGS
347389
-Wstack-protector
348390
-Wstrict-aliasing=3
349391
-Wstrict-null-sentinel
350-
-Wno-strict-overflow
392+
-Wstrict-overflow
351393
-Wstring-compare
352394
-Wstringop-overflow=4
353395
-Wstringop-overread
@@ -359,6 +401,7 @@ set(GCC_CXXFLAGS
359401
-Wsuggest-attribute=malloc
360402
-Wsuggest-attribute=noreturn
361403
-Wsuggest-attribute=pure
404+
-Wsuggest-attribute=returns_nonnull
362405
-Wsuggest-final-methods
363406
-Wsuggest-final-types
364407
-Wsuggest-override
@@ -380,6 +423,7 @@ set(GCC_CXXFLAGS
380423
-Wtsan
381424
-Wtype-limits
382425
-Wundef
426+
-Wunicode
383427
-Wuninitialized
384428
-Wunknown-pragmas
385429
-Wunreachable-code
@@ -409,6 +453,7 @@ set(GCC_CXXFLAGS
409453
-Wvolatile
410454
-Wvolatile-register-var
411455
-Wwrite-strings
456+
-Wxor-used-as-pow
412457
-Wzero-as-null-pointer-constant
413458
-Wzero-length-bounds
414459
)

0 commit comments

Comments
 (0)