Skip to content

docs: make 5 example snippets compile cleanly with clang - #22638

Closed
zaveshaa wants to merge 2 commits into
curl:masterfrom
zaveshaa:docs/fix-manpage-examples-clang
Closed

zaveshaa wants to merge 2 commits into
curl:masterfrom
zaveshaa:docs/fix-manpage-examples-clang

Conversation

@zaveshaa

Copy link
Copy Markdown
Contributor

Running .github/scripts/verify-examples.pl locally on macOS fails with 5 errors, even though CI is green. The script invokes gcc, which on macOS is clang, and clang's -Wall -pedantic -Werror is stricter than GNU gcc in two spots:

1. Passing char * to %p without a cast (-Wformat-pedantic, C11 7.21.6.1: the argument for %p shall be a pointer to void):

CURLOPT_PROGRESSDATA.md:53:27: error: format specifies type 'void *' but the argument has type 'char *'
CURLOPT_PROGRESSFUNCTION.md:99:27: error: ...
CURLOPT_XFERINFODATA.md:56:31: error: ...
CURLOPT_XFERINFOFUNCTION.md:95:26: error: ...

Fixed by casting to (void *), matching what the code already does elsewhere (e.g. (SSL*)info->internals style explicit casts in these same examples).

2. Uninitialized result in CURLINFO_TLS_SSL_PTR example (-Wsometimes-uninitialized): if curl_easy_init() returns NULL, main() returns an uninitialized CURLcode result. Initialized it to CURLE_OK, a pattern already used by other man pages.

After the change, verify-examples.pl docs/libcurl/curl*.md docs/libcurl/opts/*.md exits 0 with all 513 pages verified, both with Apple clang and (unchanged behavior) GNU gcc.

verify-examples.pl invokes 'gcc', which on macOS is clang. With
-Wall -Wextra... -Werror -pedantic, clang rejects two patterns that
GNU gcc accepts:

- passing a char * to %p without a cast (-Wformat-pedantic): the C
  standard says %p expects void *, so cast explicitly in the
  CURLOPT_PROGRESSDATA, CURLOPT_PROGRESSFUNCTION, CURLOPT_XFERINFODATA
  and CURLOPT_XFERINFOFUNCTION examples

- returning CURLcode result from main() when curl_easy_init() returned
  NULL leaves it uninitialized (-Wsometimes-uninitialized) in the
  CURLINFO_TLS_SSL_PTR example: initialize it to CURLE_OK like other
  man pages already do
Comment thread test.c Outdated
Accidentally committed the temporary file generated by
verify-examples.pl when running it locally. Spotted by bagder in
review.
@zaveshaa

Copy link
Copy Markdown
Contributor Author

Yes, a leftover by mistake — test.c is the temporary file .github/scripts/verify-examples.pl writes to repo root while verifying each snippet locally. My git add -A swept it in. Removed now, sorry for the noise!

@bagder bagder closed this in 5c61e16 Aug 22, 2026
@bagder

bagder commented Aug 22, 2026

Copy link
Copy Markdown
Member

Thanks!

vszakats added a commit that referenced this pull request Aug 26, 2026
… clang

Verify example snippets with the picky warning options used when
compiling curl core code and standalone example code. Also test with
clang. Extract picky warnings available via a new, internal, CMake
option.

Also:
- fix issues found.
- tried reproducing #22638 in CI (specifically the casts for `%p`),
  turns out it needs apple clang 17, and no longer reproducing with
  apple clang 21.

Follow-up to 5c61e16 #22638

Closes #22639
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.

2 participants