curl/src
Viktor Szakats 4497dbd9ac
clang-tidy: fixes and improvements
Fix bigger and smaller kinks in how clang-tidy is configured and used.
Sync behavior more between autotools and cmake, lib/src and tests. Bump
clang-tidy minimum version and prepare logic to allow using clang-tidy
to a fuller extent.

- move clang-tidy settings from builds to a new `.clang-tidy.yml`.
  To make it easy to see and edit checks at one place. Also to allow
  using the `--checks=` option internally to silence tests-specific
  checks. (clang-tidy does not support multiple `--check=` options via
  the command-line.)
  Use explicit `--config-file=` option to point to the configuration.
- .clang-tidy.yml: link to documentation.
- suppress `clang-diagnostic-nullability-extension` due to a false
  positive in libtests with `CURL_WERROR=ON` and `PICKY_COMPILER=OFF`.
- .clang-tidy.yml: enable `portability-*`, `misc-const-correctness`.
- drop `--quiet` clang-tidy option by default to make its working a bit
  more transparent. The extra output is minimial.
- consistently use double-dashes in clang-tidy command-line options.
  Supported by clang-tidy 9.0.0+ (2019-09-19). Before this patch single
  and double were used arbitrarily.
- src/tool_parsecfg: silence false positive `clang-analyzer-unix.Stream`.
  Seen with clang 18 + clang-tidy 19 and 20 (only with autotools.)
- INTERNALS: require clang-tidy 14.0.0+. For the `--config-file` option.
- INTERNALS: recommend clang-tidy 19.1.0+, to avoid bogus
  `clang-analyzer-valist.Uninitialized` warnings. (bug details below)

autotools:

- allow configuring the clang-tidy tool via `CLANG_TIDY` env.
  Also to use in GHA to point to a suffixed clang-tody tool.
- fix to pass CFLAGS to lib, src sources.
  (keep omitting them when using a non-clang compiler.)
- fix to pass `--warnings-as-errors=*` in quotes to avoid globbing.

cmake:

- fix to not pass an empty `-I` to clang-tidy.
- fix to pass CFLAGS (picky warnings) to clang-tidy for test sources.
  (keep omitting them when using a non-clang compiler.)
- fix to disable `clang-diagnostic-unused-function` for test sources.
  (tests have static entry points, which trigger this check when
  checking them as individidual sources.)
- fix forwarding `CURL_CLANG_TIDYFLAGS` to clang-tidy.
- force disable picky warnings when running clang-tidy with a non-clang
  compiler. To not pass these flags when checking lib and src.

CI:

- GHA/linux: avoid clang-tidy bug by upgrading to v19, and drop the
  workaround.
- GHA/linux: switch to clang from gcc in the clang-tidy job. Using gcc
  doesn't allow passing CFLAGS to clang-tidy, making it less effective.
  (My guess this was one factor contributing to this job often missing
  to find certain issues compared to GHA/macos.)

I recomment using clang-tidy with a clang compiler, preferably the same
version or one that's compatible. Other cases are best effort, and may
fail if a C flag is passed to clang-tidy that it does not understand.
Picky warnings are mostly omitted when using a non-clang compiler,
reducing its usefulness.

Details and reproducer for the v18 (and earlier) clang-tidy bug,
previously affecting the GHA/linux job:

clang-tidy <=18 emits false warnings way when passing multiple C sources
at once (as done with autotools):

```sh
cat > src1.c <<EOF
#include <string.h>
static void dummy(void *p) { memcmp(p, p, 0); }
EOF

cat > src2.c <<EOF
#include <stdarg.h>
void vafunc(int option, ...)
{
  va_list param;
  va_start(param, option);
  if(option)
    (void)va_arg(param, int);
  va_end(param);
}
EOF

/opt/homebrew/opt/llvm@18/bin/clang-tidy --checks=clang-analyzer-valist.Uninitialized src1.c src2.c

# src2.c:7:11: warning: va_arg() is called on an uninitialized va_list [clang-analyzer-valist.Uninitialized]
```

Follow-up to e86542038d #17047

Closes #20605
2026-02-19 00:02:11 +01:00
..
toolx localtime: detect thread-safe alternatives and use them 2025-12-16 14:30:06 +01:00
.checksrc checksrc: disallow atoi and atol globally 2025-11-13 14:28:25 +01:00
.gitignore rtmp: remove no longer used proto member 2025-05-08 10:24:19 +02:00
CMakeLists.txt cmake: add CURL_DROP_UNUSED option to reduce binary sizes 2026-01-22 17:08:20 +01:00
config2setopts.c src: simplify declaring curl_ca_embed 2026-02-15 12:48:46 +01:00
config2setopts.h curl: remove the global argument from many functions 2025-07-10 23:28:31 +02:00
curl.rc build: merge TrackMemory (CURLDEBUG) into debug-enabled option 2026-01-19 18:43:17 +01:00
curlinfo.c build: use more const 2026-02-02 12:32:49 +01:00
Makefile.am clang-tidy: fixes and improvements 2026-02-19 00:02:11 +01:00
Makefile.inc build: tidy up and simplify setmode() detection and use 2026-02-08 15:47:47 +01:00
mk-file-embed.pl src: simplify declaring curl_ca_embed 2026-02-15 12:48:46 +01:00
mkhelp.pl tidy-up: miscellaneous 2026-02-12 14:52:16 +01:00
slist_wc.c tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
slist_wc.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
terminal.c tidy-up: miscellaneous 2026-02-01 00:54:23 +01:00
terminal.h curl: make warnings and other messages aware of terminal width 2024-05-28 23:12:32 +02:00
tool_cb_dbg.c build: drop more forward function declarations 2026-01-14 23:34:05 +01:00
tool_cb_dbg.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_hdr.c build: tidy up and dedupe strdup functions 2026-02-03 14:02:30 +01:00
tool_cb_hdr.h tool_cb_hrd: remove global pointer from 'struct HdrCbData' 2025-08-05 15:47:56 +02:00
tool_cb_prg.c tool_cb_prg: drop duplicate preprocessor logic 2026-02-05 23:46:49 +01:00
tool_cb_prg.h tidy-up: miscellaneous 2025-12-18 21:27:58 +01:00
tool_cb_rea.c tidy-up: miscellaneous 2026-02-12 14:52:16 +01:00
tool_cb_rea.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_see.c build: tidy up local lseek() mappings 2026-02-01 17:29:39 +01:00
tool_cb_see.h tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_cb_soc.c checksrc: ensure using ifdef/ifndef when possible, fix fallouts 2025-12-21 21:12:31 +01:00
tool_cb_soc.h curl: (on linux) add MPTCP support 2024-06-07 10:54:19 +02:00
tool_cb_wrt.c build: use native file open flags in Windows-specific code 2026-02-04 15:59:35 +01:00
tool_cb_wrt.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cfgable.c tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_cfgable.h tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_dirhie.c build: update to not need _CRT_NONSTDC_NO_DEPRECATE with MSVC 2026-01-20 23:19:54 +01:00
tool_dirhie.h src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_doswin.c build: fix -Wunused-macros warnings, and related tidy-ups 2026-02-19 00:00:48 +01:00
tool_doswin.h tool: improve error/warning messages when output filename sanitization fails 2026-01-10 13:21:27 +01:00
tool_easysrc.c tool: rename curl handle and result variable in --libcurl-generated code 2026-01-26 13:21:46 +01:00
tool_easysrc.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_filetime.c build: move curl stat struct type to the curlx namespace 2026-02-04 02:07:16 +01:00
tool_filetime.h tool_filetime: sync dummy macro signature with function prototype 2026-01-12 16:29:32 +01:00
tool_findfile.c build: update to not need _CRT_NONSTDC_NO_DEPRECATE with MSVC 2026-01-20 23:19:54 +01:00
tool_findfile.h windows: use built-in _WIN32 macro to detect Windows 2023-11-22 15:42:25 +00:00
tool_formparse.c build: tidy up and simplify setmode() detection and use 2026-02-08 15:47:47 +01:00
tool_formparse.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_getparam.c tidy-up: miscellaneous 2026-02-12 14:52:16 +01:00
tool_getparam.h tidy-up: miscellaneous 2026-01-20 12:37:56 +01:00
tool_getpass.c build: update to not need _CRT_NONSTDC_NO_DEPRECATE with MSVC 2026-01-20 23:19:54 +01:00
tool_getpass.h code: language cleanup in comments 2024-07-01 22:58:55 +02:00
tool_help.c src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_help.h tool_help.h: drop redundant U suffix from literals 2026-01-29 22:53:22 +01:00
tool_helpers.c build: use more const 2026-02-02 12:32:49 +01:00
tool_helpers.h build: use more const 2026-02-02 12:32:49 +01:00
tool_hugehelp.h build: drop tool_hugehelp.c.cvs, tidy up macros, drop buildconf.bat 2025-01-26 14:22:49 +01:00
tool_ipfs.c tidy-up: miscellaneous 2026-02-01 00:54:23 +01:00
tool_ipfs.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_libinfo.c build: merge TrackMemory (CURLDEBUG) into debug-enabled option 2026-01-19 18:43:17 +01:00
tool_libinfo.h build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_listhelp.c curl: add -I and -i to -h important 2026-02-05 17:20:29 +01:00
tool_main.c socket: check result of SO_NOSIGPIPE 2026-01-20 16:38:49 +01:00
tool_main.h src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_msgs.c src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_msgs.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_operate.c src: simplify declaring curl_ca_embed 2026-02-15 12:48:46 +01:00
tool_operate.h build: use more const 2026-02-02 12:32:49 +01:00
tool_operhlp.c tidy-up: miscellaneous 2026-02-01 00:54:23 +01:00
tool_operhlp.h tool: improve error/warning messages when output filename sanitization fails 2026-01-10 13:21:27 +01:00
tool_paramhlp.c tool: return code variable consistency 2026-01-25 15:58:56 +01:00
tool_paramhlp.h src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_parsecfg.c clang-tidy: fixes and improvements 2026-02-19 00:02:11 +01:00
tool_parsecfg.h tool: log when loading .curlrc in verbose mode 2025-11-25 16:06:27 +01:00
tool_progress.c tool_progress: fix large time outputs and decimal size display 2026-01-04 00:16:59 +01:00
tool_progress.h tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_sdecls.h tool_cb_hdr: with -J, use the redirect name as a backup 2026-01-26 12:53:03 +01:00
tool_setopt.c tidy-up: miscellaneous 2026-02-12 14:52:16 +01:00
tool_setopt.h src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_setup.h src: simplify declaring curl_ca_embed 2026-02-15 12:48:46 +01:00
tool_ssls.c tool: return code variable consistency 2026-01-25 15:58:56 +01:00
tool_ssls.h src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_stderr.c tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_stderr.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_urlglob.c build: tidy up and dedupe strdup functions 2026-02-03 14:02:30 +01:00
tool_urlglob.h tool: improve error/warning messages when output filename sanitization fails 2026-01-10 13:21:27 +01:00
tool_util.c build: tidy up local lseek() mappings 2026-02-01 17:29:39 +01:00
tool_util.h build: drop Windows CE / CeGCC support 2025-11-15 15:35:23 +01:00
tool_version.h src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_vms.c src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_vms.h tidy-up: miscellaneous 2026-02-01 00:54:23 +01:00
tool_writeout.c build: use more const 2026-02-02 12:32:49 +01:00
tool_writeout.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_writeout_json.c tidy-up: miscellaneous 2025-12-18 21:27:58 +01:00
tool_writeout_json.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_xattr.c tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_xattr.h src: fix formatting nits 2025-12-03 20:50:18 +01:00
var.c build: fix -Wunused-macros warnings, and related tidy-ups 2026-02-19 00:00:48 +01:00
var.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00