Skip to content

curl/curl.h: replace recursive macros with C++-friendly method to enforce 3 args#20709

Closed
vszakats wants to merge 5 commits intocurl:masterfrom
vszakats:cpp2
Closed

curl/curl.h: replace recursive macros with C++-friendly method to enforce 3 args#20709
vszakats wants to merge 5 commits intocurl:masterfrom
vszakats:cpp2

Conversation

@vszakats
Copy link
Copy Markdown
Member

@vszakats vszakats commented Feb 24, 2026

Certain uses may still trigger a C compiler warning
-Wdisabled-macro-expansion after this, e.g. when the call is wrapped
in the CURL_IGNORE_DEPRECATION() macro as seen in docs/examples.

Suggested-by: Kai Pastor
Ref: #20682 (comment)

Follow-up to ee9b000 #20686
Follow-up to daa6b27 #20597


With warnings temporarily re-enabled unrelated CI failures expected
due to recursive macros in 3rd-party headers.

@vszakats vszakats changed the title curl/curl.h: try C++-friendly, non-recursive solution curl/curl.h: try C++-friendly, non-recursive way to enforce 3 arguments Feb 24, 2026
@vszakats vszakats changed the title curl/curl.h: try C++-friendly, non-recursive way to enforce 3 arguments curl/curl.h: try C++-friendly, non-recursive way to enforce 3 args Feb 24, 2026
@vszakats
Copy link
Copy Markdown
Member Author

vszakats commented Feb 24, 2026

It works to avoid recursive warnings in libcurl code, e.g. doh.c.
No word yet on the C++ CI job because arm runners seem to be
down.

And there is this particular case, where the call is wrapper in
CURL_IGNORE_DEPRECATION(), where the warning remains:

docs/examples/multi-formadd.c:94:9: error: disabled expansion of recursive macro [clang-diagnostic-disabled-macro-expansion,-warnings-as-errors]
   94 |         curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
      |         ^
/Users/runner/work/curl/curl/include/curl/curl.h:3335:3: note: expanded from macro 'curl_easy_setopt'
 3335 |   curl_easy_setopt curl_exactly_three_arguments(handle, opt, param)
      |   ^
301 warnings generated.

https://github.com/curl/curl/actions/runs/22349795920/job/64673656914?pr=20709

same with the bare compiler (w/o clang-tidy):

docs/examples/postit2-formadd.c:96:7: error: disabled expansion of recursive macro [-Werror,-Wdisabled-macro-expansion]
   96 |       curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
      |       ^
include/curl/curl.h:3335:3: note: expanded from macro 'curl_easy_setopt'
 3335 |   curl_easy_setopt curl_exactly_three_arguments(handle, opt, param)
      |   ^
1 error generated.

In itself a niche case, but I find it interesting.

@vszakats vszakats changed the title curl/curl.h: try C++-friendly, non-recursive way to enforce 3 args curl/curl.h: replace recursive macros with C++-friendly way for enforcing 3 args Feb 24, 2026
@vszakats
Copy link
Copy Markdown
Member Author

@aisle-analyzer augment review

@aisle-research-bot
Copy link
Copy Markdown

aisle-research-bot bot commented Feb 24, 2026

🔒 Aisle Security Analysis

✅ We scanned this PR and did not find any security vulnerabilities.

Aisle supplements but does not replace security review.


Analyzed PR: #20709 at commit ee0ec12

@vszakats vszakats requested a review from Copilot February 24, 2026 15:24
@vszakats vszakats changed the title curl/curl.h: replace recursive macros with C++-friendly way for enforcing 3 args curl/curl.h: replace recursive macros with C++-friendly method to enforce 3 args Feb 24, 2026
@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Feb 24, 2026

🤖 Augment PR Summary

Summary: Reworks the public curl_easy_setopt/curl_easy_getinfo/curl_share_setopt/curl_multi_setopt 3-argument enforcement macros to avoid self-recursive macro expansion that can trip C++/clang warnings.
Why: Improves compatibility with C++ and reduces occurrences of -Wdisabled-macro-expansion stemming from the previous recursive-macro approach.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces recursive macros with a C++-friendly two-stage macro solution for enforcing exactly three arguments to curl functions (curl_easy_setopt, curl_easy_getinfo, curl_share_setopt, curl_multi_setopt). The previous recursive macro approach broke C++ code that used the :: namespace qualifier (e.g., ::curl_easy_setopt(...)) and an alternative non-recursive approach using parentheses (curl_easy_setopt) also broke this C++ pattern. The new two-stage solution uses a helper macro curl_exactly_three_arguments that expands to parenthesized arguments, avoiding both the recursive macro warnings and the C++ compatibility issues.

Changes:

  • Introduced curl_exactly_three_arguments helper macro and updated four function macros to use the two-stage expansion pattern
  • Updated comments in build configuration files to reflect that recursive macro warnings from curl/curl.h now only occur in rare combinations rather than always

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
include/curl/curl.h Replaced recursive macros with two-stage solution using curl_exactly_three_arguments helper macro for four functions
m4/curl-compilers.m4 Updated comment to indicate -Wdisabled-macro-expansion warning is now primarily from standard headers, only rarely from curl/curl.h
CMake/PickyWarnings.cmake Updated comment to match the m4 file change regarding warning source

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vszakats vszakats added the feature-window A merge of this requires an open feature window label Feb 25, 2026
@vszakats vszakats closed this in f45bf74 Mar 21, 2026
@vszakats vszakats deleted the cpp2 branch March 21, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-window A merge of this requires an open feature window libcurl API

Development

Successfully merging this pull request may close these issues.

2 participants