From f45bf74b5a1030ac68316b22c60c73f6ab38e2c4 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 24 Feb 2026 12:45:59 +0100 Subject: [PATCH] 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 ee9b000438bd6e4cecc8a933804397a55ad0f7b8 #20686 Follow-up to daa6b27b4d998d62c8198b4fe167199cc7bf0064 #20597 Closes #20709 --- CMake/PickyWarnings.cmake | 3 ++- include/curl/curl.h | 17 +++++++++-------- m4/curl-compilers.m4 | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CMake/PickyWarnings.cmake b/CMake/PickyWarnings.cmake index 704b4bf32c..d53556d0c4 100644 --- a/CMake/PickyWarnings.cmake +++ b/CMake/PickyWarnings.cmake @@ -163,7 +163,8 @@ if(PICKY_COMPILER) if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.1) list(APPEND _picky_enable -Wno-covered-switch-default # clang 3.1 appleclang 3.1 # Annoying to fix or silence - -Wno-disabled-macro-expansion # clang 3.1 appleclang 3.1 # Triggered by curl/curl.h, standard headers + -Wno-disabled-macro-expansion # clang 3.1 appleclang 3.1 # Triggered by standard headers, + # and curl/curl.h (in rare combinations) ) if(MSVC) list(APPEND _picky_enable diff --git a/include/curl/curl.h b/include/curl/curl.h index 391e2dfd3b..faff3ab1fb 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -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 */ diff --git a/m4/curl-compilers.m4 b/m4/curl-compilers.m4 index 4c2a0befa1..5519d48e6f 100644 --- a/m4/curl-compilers.m4 +++ b/m4/curl-compilers.m4 @@ -869,7 +869,7 @@ AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [ if test "$compiler_num" -ge "301"; then CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [format-non-iso]) tmp_CFLAGS="$tmp_CFLAGS -Wno-covered-switch-default" # Annoying to fix or silence - tmp_CFLAGS="$tmp_CFLAGS -Wno-disabled-macro-expansion" # Triggered by curl/curl.h, standard headers + tmp_CFLAGS="$tmp_CFLAGS -Wno-disabled-macro-expansion" # Triggered by standard headers, and curl/curl.h (in rare combinations) fi # dnl Only clang 3.2 or later