tidy-up: delete, comment or scope C macros reported unused#16279
Closed
vszakats wants to merge 43 commits intocurl:masterfrom
Closed
tidy-up: delete, comment or scope C macros reported unused#16279vszakats wants to merge 43 commits intocurl:masterfrom
vszakats wants to merge 43 commits intocurl:masterfrom
Conversation
vszakats
commented
Feb 9, 2025
vszakats
commented
Feb 9, 2025
| #else /* No system or TLS backend SHA-512/256 implementation available */ | ||
|
|
||
| /* Use local implementation */ | ||
| #define HAS_SHA512_256_IMPLEMENTATION 1 |
Member
Author
There was a problem hiding this comment.
I'm not sure about the intent here, the macro is set twice after the last use.
Hopefully the code is OK.
vszakats
commented
Feb 9, 2025
| # define DEBUG_OUT(x) x | ||
| #else | ||
| # define DEBUG_OUT(x) Curl_nop_stmt | ||
| #endif |
Member
Author
There was a problem hiding this comment.
It'd be ideal to replace this with TRC logging, esp. in vauth/ntlm.c guard some log output behind its own DEBUG_ME macro.
vszakats
commented
Feb 9, 2025
vszakats
commented
Feb 9, 2025
| #define CURL_MASK_SLONG (CURL_MASK_ULONG >> 1) | ||
|
|
||
| #define CURL_MASK_UCOFFT ((unsigned CURL_TYPEOF_CURL_OFF_T)~0) | ||
| #define CURL_MASK_SCOFFT (CURL_MASK_UCOFFT >> 1) |
Member
Author
There was a problem hiding this comment.
Also a series/set. I surmised it's unlikely these get used given warnless hasn't been expanding for a good while.
… source Fixes unused macro warning: ``` tests/http/clients/ws-data.c:44:0: warning: macro "WIN32_LEAN_AND_MEAN" is not used [-Wunused-macros] ```
``` docs/examples/externalsocket.c:30:0: warning: macro "_WINSOCK_DEPRECATED_NO_WARNINGS" is not used [-Wunused-macros] lib/dynbuf.c:35: warning: macro "DYNINIT" is not used [-Wunused-macros] lib/version.c:426:0: warning: macro "idn_present" is not used [-Wunused-macros] src/tool_doswin.c:49:0: warning: macro "_use_lfn" is not used [-Wunused-macros] ```
``` lib/cf-socket.c:940:0: warning: macro "NW_RECV_CHUNK_SIZE" is not used [-Wunused-macros] lib/cf-socket.c:941:0: warning: macro "NW_RECV_CHUNKS" is not used [-Wunused-macros] lib/cf-socket.c:942:0: warning: macro "NW_SMALL_READS" is not used [-Wunused-macros] ```
``` lib/content_encoding.c:68:0: warning: macro "DECOMPRESS_BUFFER_SIZE" is not used [-Wunused-macros] ```
``` lib/curl_ntlm_core.c:147:0: warning: macro "NTLMv2_BLOB_SIGNATURE" is not used [-Wunused-macros] lib/curl_ntlm_core.c:148:0: warning: macro "NTLMv2_BLOB_LEN" is not used [-Wunused-macros] ```
``` lib/curl_sha512_256.c:273:0: warning: macro "HAS_SHA512_256_IMPLEMENTATION" is not used [-Wunused-macros] ```
``` lib/doh.c:50:0: warning: macro "LOCAL_PB_HEXMAX" is not used [-Wunused-macros] ```
There is a copy of this in vauth/ntlm.c, which is used. It'd be nice to migrate these to curl_trc(). ``` lib/http_ntlm.c:61:0: warning: macro "DEBUG_OUT" is not used [-Wunused-macros] ```
``` lib/inet_ntop.c:41:0: warning: macro "INADDRSZ" is not used [-Wunused-macros] ```
``` lib/url.c:840:0: warning: macro "ssh_config_matches" is not used [-Wunused-macros] ```
``` lib/vauth/digest.c:53:0: warning: macro "SESSION_ALGO" is not used [-Wunused-macros] lib/vauth/digest.c:55:0: warning: macro "ALGO_MD5" is not used [-Wunused-macros] lib/vauth/digest.c:56:0: warning: macro "ALGO_MD5SESS" is not used [-Wunused-macros] lib/vauth/digest.c:57:0: warning: macro "ALGO_SHA256" is not used [-Wunused-macros] lib/vauth/digest.c:58:0: warning: macro "ALGO_SHA256SESS" is not used [-Wunused-macros] lib/vauth/digest.c:59:0: warning: macro "ALGO_SHA512_256" is not used [-Wunused-macros] lib/vauth/digest.c:60:0: warning: macro "ALGO_SHA512_256SESS" is not used [-Wunused-macros] ```
``` lib/vtls/schannel.c:236:0: warning: macro "LONGEST_ALG_ID" is not used [-Wunused-macros] ```
``` lib/vtls/schannel.c:84:0: warning: macro "BCRYPT_CHACHA20_POLY1305_ALGORITHM" is not used [-Wunused-macros] ```
``` tests/server/mqttd.c:97:0: warning: macro "MQTT_CONNACK_LEN" is not used [-Wunused-macros] tests/server/mqttd.c:98:0: warning: macro "MQTT_SUBACK_LEN" is not used [-Wunused-macros] tests/server/mqttd.c:99:0: warning: macro "MQTT_CLIENTID_LEN" is not used [-Wunused-macros] ```
``` lib/mqtt.c:50:0: warning: macro "MQTT_MSG_CONNACK" is not used [-Wunused-macros] tests/server/mqttd.c:92:0: warning: macro "MQTT_MSG_PUBACK" is not used [-Wunused-macros] ```
``` lib/smb.c:80:0: warning: macro "SMB_FLAGS2_UNICODE_STRINGS" is not used [-Wunused-macros] ```
``` lib/vtls/x509asn1.c:79:0: warning: macro "CURL_ASN1_OBJECT_DESCRIPTOR" is not used [-Wunused-macros] lib/vtls/x509asn1.c:80:0: warning: macro "CURL_ASN1_INSTANCE_OF" is not used [-Wunused-macros] lib/vtls/x509asn1.c:81:0: warning: macro "CURL_ASN1_REAL" is not used [-Wunused-macros] lib/vtls/x509asn1.c:83:0: warning: macro "CURL_ASN1_EMBEDDED" is not used [-Wunused-macros] lib/vtls/x509asn1.c:85:0: warning: macro "CURL_ASN1_RELATIVE_OID" is not used [-Wunused-macros] lib/vtls/x509asn1.c:86:0: warning: macro "CURL_ASN1_SEQUENCE" is not used [-Wunused-macros] lib/vtls/x509asn1.c:87:0: warning: macro "CURL_ASN1_SET" is not used [-Wunused-macros] lib/vtls/x509asn1.c:91:0: warning: macro "CURL_ASN1_VIDEOTEX_STRING" is not used [-Wunused-macros] lib/vtls/x509asn1.c:95:0: warning: macro "CURL_ASN1_GRAPHIC_STRING" is not used [-Wunused-macros] lib/vtls/x509asn1.c:97:0: warning: macro "CURL_ASN1_GENERAL_STRING" is not used [-Wunused-macros] lib/vtls/x509asn1.c:99:0: warning: macro "CURL_ASN1_CHARACTER_STRING" is not used [-Wunused-macros] ```
``` src/tool_setopt.c:188:0: warning: macro "DECL0" is not used [-Wunused-macros] src/tool_setopt.c:191:0: warning: macro "DATA0" is not used [-Wunused-macros] src/tool_setopt.c:193:0: warning: macro "DATA2" is not used [-Wunused-macros] src/tool_setopt.c:201:0: warning: macro "CLEAN0" is not used [-Wunused-macros] src/tool_setopt.c:204:0: warning: macro "REM0" is not used [-Wunused-macros] src/tool_setopt.c:205:0: warning: macro "REM1" is not used [-Wunused-macros] ```
```
/Users/runner/work/curl/curl/lib/parsedate.c:103:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
103 | #define PARSEDATE_SOONER 2
| ^
1 warning generated.
```
https://github.com/curl/curl/actions/runs/13232157963/job/36930964574?pr=16279#step:11:111
`SSLEAY_VERSION_NUMBER` is pending deletion in a separate PR.
Curious `OPENSSL_HAS_PROVIDERS` and `HAVE_ERR_REMOVE_THREAD_STATE`. No clear fix?
```
/Users/runner/work/curl/curl/lib/vtls/openssl.c:110:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
110 | #define OPENSSL_HAS_PROVIDERS
| ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:141:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
141 | #define HAVE_ERR_REMOVE_THREAD_STATE 1
| ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:147:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
147 | #define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
| ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:158:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
158 | #define ARG2_X509_signature_print
| ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:859:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
859 | #define RAND_LOAD_LENGTH 1024
| ^
5 warnings generated.
```
https://github.com/curl/curl/actions/runs/13232249007/job/36931188045?pr=16279#step:11:195
Fixing this isn't pracitcal.
This reverts commit e8126db.
The `CM clang OpenSSL AppleIDN clang-tidy +examples` job is finding
further cases, and due to clang-tidy it flags them as errors and
fails on the first one. I stopped cleaning up at `openssl.c` when
bumping into these non-trivial cases to silence:
```
/Users/runner/work/curl/curl/lib/vtls/openssl.c:110:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
110 | #define OPENSSL_HAS_PROVIDERS
| ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:141:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
141 | #define HAVE_ERR_REMOVE_THREAD_STATE
| ^
```
https://github.com/curl/curl/actions/runs/13232573832/job/36932009939?pr=16279#step:11:195
pps83
pushed a commit
to pps83/curl
that referenced
this pull request
Apr 26, 2025
To reduce the number `-Wunused-macro` compiler warnings: - delete unused macros. - comment out unused macro that are part of a set. - move macros into the scope they are used. This may be useful to enable by default, but there are tricky cases that I didn't manage to fix and paused the effort. E.g. internal features checks in `openssl.c`. There is more, once those are fixed. Closes curl#16279
vszakats
added a commit
to vszakats/curl
that referenced
this pull request
Sep 5, 2025
5 tasks
vszakats
added a commit
to vszakats/curl
that referenced
this pull request
Sep 19, 2025
vszakats
added a commit
that referenced
this pull request
Sep 20, 2025
To avoid hitting `-Wreserved-macro-identifier` where possible. - amigaos: introduce local macro instead of reusing `__request()`. - easy_lock: avoid redefining `__has_builtin()`. Follow-up to 33fd57b #9062 - rand: drop interim macro `_random()`. - windows: rename local macro `_tcsdup()` to `Curl_tcsdup()`. To avoid using the reserved macro namespace and to avoid colliding with `_tcsdup()` as defined by Windows headers. - checksrc: ban `_tcsdup()` in favor of `Curl_tcsdup()`. - tool_doswin: avoid redefining `_use_lfn()` (MS-DOS). - tool_findfile: limit `__NO_NET_API` hack to AmigaOS. Syncing this pattern with `lib/netrc.c`. Follow-up to 784a8ec #16279 - examples/http2-upload: avoid reserved namespace for local macro. More cases will be removed when dropping WinCE support via #17927. Cases remain when defining external macros out of curl's control. Ref: #18477 Closes #18482
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To reduce the number
-Wunused-macrocompiler warnings:This may be useful to enable by default, but there are tricky cases that
I didn't manage to fix and paused the effort. E.g. internal features
checks in
openssl.c. There is more, once those are fixed.CurlTests.cpatch. → build: fix compiler warnings in feature detections #16287