Skip to content

build: address some -Weverything warnings, update picky warnings#18477

Closed
vszakats wants to merge 88 commits intocurl:masterfrom
vszakats:wmore
Closed

build: address some -Weverything warnings, update picky warnings#18477
vszakats wants to merge 88 commits intocurl:masterfrom
vszakats:wmore

Conversation

@vszakats
Copy link
Copy Markdown
Member

@vszakats vszakats commented Sep 4, 2025

-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.
    clang 17.0.2: No "unreachable code" warning if source file included in another source file 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):

CMake PICKY_COMPILER=ON (the default) or ./configure
--enable-warnings (not the default) is required to enable these
silencing rules.

Also:

Follow-up to b85cb8c #18485


w/o sp https://github.com/curl/curl/pull/18477/files?w=1

  • enable warnings that were silenced in-source via this patch
  • fixup clang version guard for Apple clang
  • apply cmake changes to autotools too
  • rebase on spacecheck: warn for 3+ empty lines in a row, fix fallouts #18478
  • consider disabling -Wcast-function-type-strict globally? → Leaving them there for "awareness". But, there seems to be no way to fix these in most cases, because the callback types are either part of the public curl APIs, or part of public external APIs. In url.c it may be possible to wrap fwrite/fread in internal functions to match the signature exactly, but it's even more noise (and runtime perf hit) with no benefit for current code.

@vszakats vszakats added the build label Sep 4, 2025
@vszakats vszakats changed the title build: silence rare compiler warnings build: silence some -Weverything warnings Sep 4, 2025
@vszakats
Copy link
Copy Markdown
Member Author

vszakats commented Sep 4, 2025

Standing at:

6782 -Wunsafe-buffer-usage
 985 -Wformat
  12 -Wc++-hidden-decl
   8 -Wformat-non-iso

@vszakats
Copy link
Copy Markdown
Member Author

vszakats commented Sep 4, 2025

Down to 985 -Wformat.

They are addressed via pending #18343.

@vszakats vszakats marked this pull request as draft September 4, 2025 13:12
@vszakats vszakats changed the title build: silence some -Weverything warnings build: silence some llvm/clang -Weverything warnings Sep 4, 2025
@vszakats vszakats changed the title build: silence some llvm/clang -Weverything warnings build: silence some -Weverything warnings Sep 4, 2025
@vszakats vszakats changed the title build: silence some -Weverything warnings build: fix/silence some -Weverything warnings Sep 4, 2025
@vszakats vszakats marked this pull request as ready for review September 5, 2025 08:00
@vszakats vszakats changed the title build: fix/silence some -Weverything warnings build: address most -Weverything warnings Sep 5, 2025
vszakats added a commit to vszakats/curl that referenced this pull request Sep 7, 2025
It's a `-Weverything` warning that appeared in llvm/clang 21.

```
lib/openldap.c:1297:19: warning: duplicate declaration of 'ldapsb_tls' is invalid in C++ [-Wtentative-definition-compat]
 1297 | static Sockbuf_IO ldapsb_tls =
      |                   ^
lib/openldap.c:499:19: note: previous declaration is here
  499 | static Sockbuf_IO ldapsb_tls;
      |                   ^
```

Reported-by: correctmost on github
Fixes curl#18470
Cherry-picked from curl#18477
vszakats added a commit that referenced this pull request Sep 7, 2025
It's a `-Weverything` warning that appeared in llvm/clang 21.

```
lib/openldap.c:1297:19: warning: duplicate declaration of 'ldapsb_tls' is invalid in C++ [-Wtentative-definition-compat]
 1297 | static Sockbuf_IO ldapsb_tls =
      |                   ^
lib/openldap.c:499:19: note: previous declaration is here
  499 | static Sockbuf_IO ldapsb_tls;
      |                   ^
```

Reported-by: correctmost on github
Fixes #18470
Cherry-picked from #18477
Closes #18485
@vszakats
Copy link
Copy Markdown
Member Author

vszakats commented Sep 7, 2025

Azure Ubuntu mirrors superslow again.

@vszakats vszakats changed the title build: address most -Weverything warnings build: address some -Weverything warnings Sep 8, 2025
@vszakats
Copy link
Copy Markdown
Member Author

vszakats commented Sep 8, 2025

Some interesting edge cases and weird fallouts after enabling -Weverything in CI (as a one-time test):

  • clang-tidy trips on the -Wimplicit-void-ptr-cast warning (clang-diagnostic-implicit-void-ptr-cast),
    likely because the warning isn't disabled, because the build uses Apple clang which doesn't support this option yet,
    but the clang-tidy tool is picked from Homebrew llvm, which does. (Apple clang doesn't ship with clang-tidy.)
    https://github.com/curl/curl/actions/runs/17558369300/job/49868303278?pr=18477
  • The Xcode generator seems to be adding an include directory which doesn't exists, tripping -Wmissing-include-dirs. Only seen with iOS.
    https://github.com/curl/curl/actions/runs/17558369300/job/49868302983?pr=18477
    It seems like a CMake issue.
    [...] -Wno-semicolon-before-method-body -I/Users/runner/work/curl/curl/bld/lib/Debug-iphoneos/include -I/Users/runner/work/curl/curl/include -I/Users/runner/work/curl/curl/bld/lib -isystem /Users/runner/libressl/include -I/Users/runner/work/curl/curl/bld/build/libcurl_shared.build/Debug-iphoneos/DerivedSources-normal/arm64 -I/Users/runner/work/curl/curl/bld/build/libcurl_shared.build/Debug-iphoneos/DerivedSources/arm64 -I/Users/runner/work/curl/curl/bld/build/libcurl_shared.build/Debug-iphoneos/DerivedSources -F/Users/runner/work/curl/curl/bld/lib/Debug-iphoneos -fPIC -fvisibility\=hidden [...]
    [...]
    clang: error: no such include directory: '/Users/runner/work/curl/curl/bld/lib/Debug-iphoneos/include' [-Werror,-Wmissing-include-dirs]
    clang: error: no such include directory: '/Users/runner/work/curl/curl/bld/build/libcurl_shared.build/Debug-iphoneos/DerivedSources-normal/arm64' [-Werror,-Wmissing-include-dirs]
    clang: error: no such include directory: '/Users/runner/work/curl/curl/bld/build/libcurl_shared.build/Debug-iphoneos/DerivedSources/arm64' [-Werror,-Wmissing-include-dirs]
    clang: error: no such include directory: '/Users/runner/work/curl/curl/bld/build/libcurl_shared.build/Debug-iphoneos/DerivedSources' [-Werror,-Wmissing-include-dirs]
    
  • OpenBSD dies with LLVM ERROR: out of memory when compiling libtests.
    https://github.com/curl/curl/actions/runs/17558369306/job/49868302856?pr=18477#step:3:2015
  • FreeBSD exhibits this warning:
    /home/runner/work/curl/curl/lib/mime.c:363:17: error: '_Generic' is incompatible with C standards before C11 [-Werror,-Wpre-c11-compat]
      363 |   base = strdup(basename(filename));
          |                 ^
    /usr/include/libgen.h:60:21: note: expanded from macro 'basename'
       60 | #define basename(x)     __generic(x, const char *, __old_basename, basename)(x)
          |                         ^
    /usr/include/sys/cdefs.h:314:2: note: expanded from macro '__generic'
      314 |         _Generic(expr, t: yes, default: no)
          |         ^
    1 error generated.
    
    https://github.com/curl/curl/actions/runs/17558369306/job/49868302863?pr=18477#step:3:1996

```
/Users/runner/work/curl/curl/lib/asyn-ares.c:72:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
   72 | #define HAVE_CARES_IPV6 1
      |         ^
/Users/runner/work/curl/curl/lib/asyn-ares.c:111:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
  111 | #define HAPPY_EYEBALLS_DNS_TIMEOUT 5000
      |         ^
2 warnings generated.
```
https://github.com/curl/curl/actions/runs/17561982725/job/49880306836?pr=18477#step:11:32
…-identifier`

sync with lib/netrc.c

```
src/tool_findfile.c:27:8: warning: macro name is a reserved identifier [-Wreserved-macro-identifier]
   27 | #undef __NO_NET_API /* required for AmigaOS to declare getpwuid() */
      |        ^
src/tool_findfile.c:29:9: warning: macro name is a reserved identifier [-Wreserved-macro-identifier]
   29 | #define __NO_NET_API
      |         ^
```
This reverts commit d2c2429.

Still too noisy.

- lib/vauth/ntlm.c: some `NTLMFLAG_*` macros are only used when
  `DEBUG_ME` is defined.
- lib/md5.c: `USE_OPENSSL_MD5` and `USE_WOLFSSL_MD5` can be defined
  without being used in MultiSSL builds.
- lib/asyn-ares.c: `HAVE_CARES_IPV6` is defined but not used.
  easy to fix, but it'd be better to bump minimum c-ares to 1.6.1.
- lib/vtls/wolfssl.c: `WOLFSSL_OPTIONS_IGNORE_SYS` defined, detected
  as unused. Workaround is ugly by moving this to the command-line.
Using the flag as a regex, and a + (as in c++) in it makes this break.
llvm/clang 21 introduces warning flags with '+' signs in them.

```
-- CMake platform flags: UNIX
CMake Error at CMake/PickyWarnings.cmake:335 (if):
  if given arguments:

    "_ccmatch" "AND" "-O1   -fno-omit-frame-pointer   -gline-tables-only   -Wno-error=incompatible-function-pointer-types   -Wno-error=int-conversion   -Wno-error=deprecated-declarations   -Wno-error=implicit-function-declaration   -Wno-error=implicit-int   -Wno-error=unknown-warning-option   -Wno-error=vla-cxx-extension   -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link " "MATCHES" "-Wno-c++-hidden-decl " "AND" "NOT" "_ccopt" "STREQUAL" "-Wall" "AND" "NOT" "_ccopt" "MATCHES" "^-Wno-"

  Regular expression "-Wno-c++-hidden-decl " cannot compile
Call Stack (most recent call first):
  CMakeLists.txt:272 (include)

RegularExpression::compile(): Nested *?+.
RegularExpression::compile(): Error in compile.

-- Configuring incomplete, errors occurred!
ninja: build stopped: subcommand failed.
```
@vszakats vszakats changed the title build: address some -Weverything warnings build: address some -Weverything warnings, update picky warnings Sep 20, 2025
@vszakats vszakats closed this in 92f215f Sep 20, 2025
@vszakats vszakats deleted the wmore branch September 20, 2025 08:20
vszakats added a commit that referenced this pull request Dec 9, 2025
Explicitly disable these warnings to allow using `-Weverything`.

There are around 600 of them across the codebase.

Silencing them has some drawbacks:
- enums (`CURLcode` mostly) would have to be cast to int to avoid
  different signedness depending on C compiler.
  (llvm/gcc: unsigned, MSVC/clang-cl: signed by default)
- hex masks need casts to unsigned to avoid the warning.
- fixing remaining warnings is annoying without fixing the above.
- without fixing all warnings the option cannot be enabled, to keep
  the codebase warning free.

Ref: #18343 (silenced all warnings, but without the enum cast)
Follow-up to 92f215f #18477
Closes #19907
@vszakats vszakats mentioned this pull request Feb 15, 2026
1 task
vszakats added a commit that referenced this pull request Feb 15, 2026
To fix potential `-Wdisabled-macro-expansion` warnings when using these
macros within other macros. Fixing for example:
```
lib/doh.c:328:3: error: disabled expansion of recursive macro [clang-diagnostic-disabled-macro-expansion,-warnings-as-errors]
  328 |   ERROR_CHECK_SETOPT(CURLOPT_URL, url);
      |   ^
lib/doh.c:271:14: note: expanded from macro 'ERROR_CHECK_SETOPT'
  271 |     result = curl_easy_setopt((CURL *)doh, x, y);       \
      |              ^
include/curl/curl.h:3332:44: note: expanded from macro 'curl_easy_setopt'
 3332 | #define curl_easy_setopt(handle,opt,param) curl_easy_setopt(handle,opt,param)
      |                                            ^
[...]
```

Also update comments on why curl continues to disable
`-Wdisabled-macro-expansion` and `-Wused-but-marked-unused` warnings.

Follow-up to 92f215f #18477

Closes #20597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant