Skip to content

Commit 92f215f

Browse files
committed
build: address some -Weverything warnings, update picky warnings
`-Weverything` is not enabled by curl, and not recommended by LLVM, because it may enable experimental options, and will result in new fallouts after toolchain upgrades. This patch aims to fix/silence as much as possible as found with llvm/clang 21.1.0. It also permanently enables warnings that were fixed in source and deemed manageable in the future. `-Wformat` warnings are addressed separately via #18343. Fix/silence warnings in the source: - typecheck-gcc.h: fix `-Wreserved-identifier`. - lib: silence `-Wcast-function-type-strict`. For llvm 16+ or Apple clang 16+. - asyn-ares: limit `HAPPY_EYEBALLS_DNS_TIMEOUT` to old c-ares versions. - curl_trc: fix `-Wc++-hidden-decl`. - doh: fix `-Wc++-keyword`. - ftp: fix `-Wreserved-identifier`. - ldap: fix `-Wreserved-identifier`. - mqtt: comment unused macro to avoid warning. - multi_ev: drop unused macros to avoid warnings. - setopt: fix useless `break;` after `return;`. - gtls, mbedtls, rustls: silence `-Wconditional-uninitialized`. - socks_sspi, schannel, x509asn1: fix `-Wimplicit-int-enum-cast`. - x509asn1: fix `-Wc++-keyword`. - openssl: scope `OSSL_UI_METHOD_CAST` to avoid unused macro warning. - libssh2, wolfssl: drop unused macros. - curl_ngtcp2, curl_quiche, httpsrr, urlapi: drop/limit unused macros. - tool_getparam: fix useless `break;` after `return;` or `break;`. Not normally enabled because it doesn't work with unity. llvm/llvm-project#71046 - tool_operate: fix `-Wc++-keyword`. - curlinfo: fix a `-Wunsafe-buffer-usage`. - tests: silence `-Wformat-non-iso`. - lib557: fix `-Wreserved-identifier`. - lib1565: silence `-Wconditional-uninitialized`. Enable the above clang warnings permanently in picky mode: - `-Wc++-hidden-decl` - `-Wc++-keyword` (except for Windows, where it collides with `wchar_t`) - `-Wcast-function-type-strict` - `-Wcast-function-type` - `-Wconditional-uninitialized` - `-Wformat-non-iso` (except for clang-cl) - `-Wreserved-identifier` - `-Wtentative-definition-compat` Silence problematic `-Weverything` warnings globally (in picky mode): - `-Wused-but-marked-unused` (88000+ hits) and `-Wdisabled-macro-expansion` (2600+ hits). Triggered by `typecheck-gcc.h` when building with clang 14+. Maybe there exists a way to fix within that header? Ref: https://discourse.llvm.org/t/removing-wused-but-marked-unused/55310 - `-Wunsafe-buffer-usage`. clang 16+. 7000+ hits. May be useful in theory, but such high volume of hits makes it impractical to review and possibly address. Meant for C++. Ref: https://clang.llvm.org/docs/SafeBuffers.html Ref: https://stackoverflow.com/questions/77017567/how-to-fix-code-to-avoid-warning-wunsafe-buffer-usage Ref: https://discourse.llvm.org/t/rfc-c-buffer-hardening/65734 Ref: llvm/llvm-project#111624 - `-Wimplicit-void-ptr-cast`. clang 21+. 1700+ hits. C++ warning, deemed pure noise. Ref: #18470 (comment) - `-Wswitch-default` (180+ hits), `-Wswitch-enum` (190+ hits), `-Wcovered-switch-default` (20+ hits). Next to impossible to fix cleanly, esp. when the covered `case` branches depend on compile-time options. - `-Wdocumentation-unknown-command` (8+ hits). Triggered in a few sources. Seems arbitrary and bogus. - `-Wpadded` (550+ hits). - `-Wc++-keyword` on Windows, where it collides with `wchar_t`. (100+ hits) Ref: llvm/llvm-project#155988 - `-Wreserved-macro-identifier`. clang 13+. 5+ hits. Sometimes it's necessary to set external macros that use the reserved namespace. E.g. `_CRT_NONSTDC_NO_DEPRECATE`, `__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__`, `__NO_NET_API`, possibly `_REENTRANT`, and more. It's not worth trying to silence them individually. - `-Wnonportable-system-include-path` with `clang-cl`. It'd be broken by doing what the warning suggests. - `-Wformat-non-iso` for clang-cl. CMake `PICKY_COMPILER=ON` (the default) or `./configure` `--enable-warnings` (not the default) is required to enable these silencing rules. Also: - autotools, cmake: fix Apple clang and mainline llvm version translations. Ref: https://en.wikipedia.org/wiki/Xcode#Toolchain_versions - autotools, cmake: enable `-Warray-compare` for clang 20+. Follow-up to 4b7accd #17196 - cmake: fix to enable `-Wmissing-variable-declarations` at an earlier clang version. - cmake: update internal logic to handle warning options with `+` in them. - cmake: fix internal logic to match the whole option when looking into `CMAKE_C_FLAGS` for custom-disabled warnings. Follow-up to b85cb8c #18485 Closes #18477
1 parent 87cbeec commit 92f215f

36 files changed

+532
-359
lines changed

CMake/PickyWarnings.cmake

Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ endif()
4747

4848
if(APPLE AND
4949
(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.6) OR
50-
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.3))
51-
list(APPEND _picky "-Werror=partial-availability") # clang 3.6 appleclang 6.3
50+
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.1))
51+
list(APPEND _picky "-Werror=partial-availability") # clang 3.6 appleclang 6.1
5252
endif()
5353

5454
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
@@ -87,6 +87,9 @@ if(PICKY_COMPILER)
8787
set(_picky_detect
8888
)
8989

90+
# Notes: -Wno-* options should ideally be disabled at their precise cutoff versions,
91+
# to suppress undesired warnings in case -Weverything is passed as a custom option.
92+
9093
# Assume these options always exist with both clang and gcc.
9194
# Require clang 3.0 / gcc 2.95 or later.
9295
list(APPEND _picky_enable
@@ -121,13 +124,14 @@ if(PICKY_COMPILER)
121124
-Wmissing-field-initializers # clang 2.7 gcc 4.1
122125
-Wmissing-noreturn # clang 2.7 gcc 4.1
123126
-Wno-format-nonliteral # clang 1.0 gcc 2.96 (3.0)
127+
-Wno-padded # clang 2.9 gcc 4.1 # Not used: We cannot change public structs
124128
-Wno-sign-conversion # clang 2.9 gcc 4.3
129+
-Wno-switch-default # clang 2.7 gcc 4.1 # Not used: Annoying to fix or silence
130+
-Wno-switch-enum # clang 2.7 gcc 4.1 # Not used: It basically disallows default case
125131
-Wno-system-headers # clang 1.0 gcc 3.0
126-
# -Wpadded # clang 2.9 gcc 4.1 # Not used: We cannot change public structs
127132
-Wold-style-definition # clang 2.7 gcc 3.4
128133
-Wredundant-decls # clang 2.7 gcc 4.1
129134
-Wstrict-prototypes # clang 1.0 gcc 3.3
130-
# -Wswitch-enum # clang 2.7 gcc 4.1 # Not used: It basically disallows default case
131135
-Wtype-limits # clang 2.7 gcc 4.3
132136
-Wunreachable-code # clang 2.7 gcc 4.1
133137
# -Wunused-macros # clang 2.7 gcc 4.1 # Not practical
@@ -139,6 +143,8 @@ if(PICKY_COMPILER)
139143
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
140144
list(APPEND _picky_enable
141145
${_picky_common_old}
146+
-Wconditional-uninitialized # clang 3.0
147+
-Wno-used-but-marked-unused # clang 3.0 # Triggered by typecheck-gcc.h (with clang 14+)
142148
-Wshift-sign-overflow # clang 2.9
143149
-Wshorten-64-to-32 # clang 1.0
144150
-Wformat=2 # clang 3.0 gcc 4.8
@@ -149,39 +155,102 @@ if(PICKY_COMPILER)
149155
)
150156
endif()
151157
# Enable based on compiler version
158+
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.1)
159+
list(APPEND _picky_enable
160+
-Wno-covered-switch-default # clang 3.1 appleclang 3.1 # Annoying to fix or silence
161+
-Wno-disabled-macro-expansion # clang 3.1 appleclang 3.1 # Triggered by typecheck-gcc.h (with clang 14+)
162+
)
163+
if(MSVC)
164+
list(APPEND _picky_enable
165+
-Wno-format-non-iso # clang 3.1 appleclang 3.1 # 'q' length modifier is not supported by ISO C
166+
)
167+
else()
168+
list(APPEND _picky_enable
169+
-Wformat-non-iso # clang 3.1 appleclang 3.1
170+
)
171+
endif()
172+
endif()
173+
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.3) OR
174+
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0))
175+
list(APPEND _picky_enable
176+
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.2 g++ 11.0
177+
-Wmissing-variable-declarations # clang 3.2 appleclang 4.2
178+
-Wno-documentation-unknown-command # clang 3.3 appleclang 5.0
179+
-Wsometimes-uninitialized # clang 3.2 appleclang 4.2
180+
)
181+
endif()
152182
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.6) OR
153-
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.3))
183+
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.1))
154184
list(APPEND _picky_enable
155-
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.3
156-
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.6 g++ 11.0
185+
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.1
157186
-Wheader-guard # clang 3.4 appleclang 5.1
158187
-Wpragmas # clang 3.5 gcc 4.1 appleclang 6.0
159-
-Wsometimes-uninitialized # clang 3.2 appleclang 4.6
160188
# -Wunreachable-code-break # clang 3.5 appleclang 6.0 # Not used: Silent in "unity" builds
161189
-Wunused-const-variable # clang 3.4 gcc 6.0 appleclang 5.1
162190
)
163191
endif()
164192
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.9) OR
165-
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.3))
193+
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1))
166194
list(APPEND _picky_enable
167-
-Wcomma # clang 3.9 appleclang 8.3
168-
-Wmissing-variable-declarations # clang 3.2 appleclang 4.6
195+
-Wcomma # clang 3.9 appleclang 8.1
169196
)
197+
if(MSVC)
198+
list(APPEND _picky_enable
199+
-Wno-nonportable-system-include-path # clang 3.9 appleclang 8.1 # No truly portable solution to this
200+
)
201+
endif()
170202
endif()
171203
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0) OR
172-
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.3))
204+
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11))
173205
list(APPEND _picky_enable
174-
-Wassign-enum # clang 7.0 appleclang 10.3
175-
-Wextra-semi-stmt # clang 7.0 appleclang 10.3
206+
-Wassign-enum # clang 7.0 appleclang 11.0
207+
-Wextra-semi-stmt # clang 7.0 appleclang 11.0
176208
)
177209
endif()
178210
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) OR
179-
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.4))
211+
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12))
212+
list(APPEND _picky_enable
213+
-Wimplicit-fallthrough # clang 4.0 gcc 7.0 appleclang 9.0 # We do silencing for clang 10.0 and above only
214+
-Wxor-used-as-pow # clang 10.0 gcc 13.0 appleclang 12.0
215+
)
216+
endif()
217+
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0) OR
218+
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1))
219+
list(APPEND _picky_enable
220+
-Wcast-function-type # clang 13.0 appleclang 13.1
221+
-Wreserved-identifier # clang 13.0 appleclang 13.1 # Keep it before -Wno-reserved-macro-identifier
222+
-Wno-reserved-macro-identifier # clang 13.0 appleclang 13.1 # External macros have to be set sometimes
223+
)
224+
endif()
225+
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) OR
226+
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15.0))
227+
list(APPEND _picky_enable
228+
-Wno-unsafe-buffer-usage # clang 16.0 appleclang 15.0
229+
)
230+
endif()
231+
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) OR
232+
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0))
180233
list(APPEND _picky_enable
181-
-Wimplicit-fallthrough # clang 4.0 gcc 7.0 appleclang 12.4 # We do silencing for clang 10.0 and above only
182-
-Wxor-used-as-pow # clang 10.0 gcc 13.0
234+
-Wcast-function-type-strict # clang 16.0 appleclang 16.0
183235
)
184236
endif()
237+
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 21.0)
238+
list(APPEND _picky_enable
239+
-Warray-compare # clang 20.0 gcc 12.0 appleclang ?
240+
-Wc++-hidden-decl # clang 21.0 appleclang ?
241+
-Wno-implicit-void-ptr-cast # clang 21.0 appleclang ?
242+
-Wtentative-definition-compat # clang 21.0 appleclang ?
243+
)
244+
if(WIN32)
245+
list(APPEND _picky_enable
246+
-Wno-c++-keyword # clang 21.0 appleclang ? # `wchar_t` triggers it on Windows
247+
)
248+
else()
249+
list(APPEND _picky_enable
250+
-Wc++-keyword # clang 21.0 appleclang ?
251+
)
252+
endif()
253+
endif()
185254
else() # gcc
186255
# Enable based on compiler version
187256
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.3)
@@ -207,7 +276,7 @@ if(PICKY_COMPILER)
207276
endif()
208277
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
209278
list(APPEND _picky_enable
210-
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.3
279+
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.1
211280
-Wformat=2 # clang 3.0 gcc 4.8
212281
-Wtrampolines # gcc 4.6
213282
)
@@ -232,21 +301,21 @@ if(PICKY_COMPILER)
232301
-Walloc-zero # gcc 7.0
233302
-Wduplicated-branches # gcc 7.0
234303
-Wformat-truncation=2 # gcc 7.0
235-
-Wimplicit-fallthrough # clang 4.0 gcc 7.0
304+
-Wimplicit-fallthrough # clang 4.0 gcc 7.0 appleclang 9.0
236305
-Wrestrict # gcc 7.0
237306
)
238307
endif()
239308
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
240309
list(APPEND _picky_enable
241310
-Warith-conversion # gcc 10.0
242-
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.6 g++ 11.0
311+
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.2 g++ 11.0
243312
)
244313
endif()
245314
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)
246315
list(APPEND _picky_enable
247-
-Warray-compare # clang 20.0 gcc 12.0
316+
-Warray-compare # clang 20.0 gcc 12.0 appleclang ?
248317
-Wenum-int-mismatch # gcc 13.0
249-
-Wxor-used-as-pow # clang 10.0 gcc 13.0
318+
-Wxor-used-as-pow # clang 10.0 gcc 13.0 appleclang 12.0
250319
)
251320
endif()
252321
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15.0)
@@ -262,8 +331,11 @@ if(PICKY_COMPILER)
262331

263332
set(_picky_skipped "")
264333
foreach(_ccopt IN LISTS _picky_enable)
265-
string(REGEX MATCH "-W([a-z0-9-]+)" _ccmatch "${_ccopt}")
266-
if(_ccmatch AND CMAKE_C_FLAGS MATCHES "-Wno-${CMAKE_MATCH_1}" AND NOT _ccopt STREQUAL "-Wall" AND NOT _ccopt MATCHES "^-Wno-")
334+
string(REGEX MATCH "-W([a-z0-9+-]+)" _ccmatch "${_ccopt}")
335+
string(REPLACE "+" "\\+" _cmake_match_1 "${CMAKE_MATCH_1}") # escape '+' to make it a valid regex
336+
if(_ccmatch AND "${CMAKE_C_FLAGS} " MATCHES "-Wno-${_cmake_match_1} " AND
337+
NOT _ccopt STREQUAL "-Wall" AND
338+
NOT _ccopt MATCHES "^-Wno-")
267339
string(APPEND _picky_skipped " ${_ccopt}")
268340
else()
269341
list(APPEND _picky "${_ccopt}")

0 commit comments

Comments
 (0)