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

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: https://github.com/curl/curl/issues/20682#issuecomment-3949788664

Follow-up to ee9b000438 #20686
Follow-up to daa6b27b4d #20597

Closes #20709
This commit is contained in:
Viktor Szakats 2026-02-24 12:45:59 +01:00
parent c3c2bf5941
commit f45bf74b5a
No known key found for this signature in database
3 changed files with 12 additions and 10 deletions

View file

@ -3324,18 +3324,19 @@ CURL_EXTERN CURLcode curl_easy_ssls_export(CURL *handle,
#include "typecheck-gcc.h"
#else
#if defined(__STDC__) && (__STDC__ >= 1)
/* This preprocessor magic that replaces a call with the exact same call is
only done to make sure application authors pass exactly three arguments
to these functions. Use recursive macros to allow using these symbols via
the C++ global namespace '::' or reusing them as method names. */
/* This preprocessor magic ensures that application authors pass exactly three
arguments to these functions. For compatibility with C++ global namespace
'::' and reusing these symbols as method names, while also avoiding
recursive macros, use a two-stage solution. */
#define curl_exactly_three_arguments(a, b, c) (a, b, c)
#define curl_easy_setopt(handle, opt, param) \
curl_easy_setopt(handle, opt, param)
curl_easy_setopt curl_exactly_three_arguments(handle, opt, param)
#define curl_easy_getinfo(handle, info, arg) \
curl_easy_getinfo(handle, info, arg)
curl_easy_getinfo curl_exactly_three_arguments(handle, info, arg)
#define curl_share_setopt(share, opt, param) \
curl_share_setopt(share, opt, param)
curl_share_setopt curl_exactly_three_arguments(share, opt, param)
#define curl_multi_setopt(handle, opt, param) \
curl_multi_setopt(handle, opt, param)
curl_multi_setopt curl_exactly_three_arguments(handle, opt, param)
#endif /* __STDC__ >= 1 */
#endif /* gcc >= 4.3 && !__cplusplus && !CURL_DISABLE_TYPECHECK */