Repository navigation
Conversation
It's plain weird. Don't do it.
|
I think this is a pretty strong argument against -Werror=unused-result. It is rather crazy that |
The reason to use them seems to be that just (void) before a function call is not enough to silence compiler warnings when return codes are ignored and -Werror=unused-result is used. While (void)! apparently works to silence those warnings, it is just too weird and surprising to readers to use. It is rather a reason to reconsider the usefulness of the warning. Closes #22023
| if(!serverlogfile) { | ||
| static const char msg[] = "exit_signal_handler: serverlogfile not set\n"; | ||
| (void)!write(STDERR_FILENO, msg, sizeof(msg) - 1); | ||
| rc = write(STDERR_FILENO, msg, sizeof(msg) - 1); |
There was a problem hiding this comment.
I wish I linked the compiler warning that triggered this ugly workaround
in subcommit a420aad.
Also revealing which compiler was this.
I'll fire up a test to see now.
There was a problem hiding this comment.
FTR I most likely took the (void)! fix from this link: https://stackoverflow.com/questions/40576003/ignoring-warning-wunused-result
|
This needs a combination of this GCC warning option (that's enabled Due to the many conditions it only affects these 5 CI jobs: Seems limited, and the trigger code in the signal handler is kind of special. |
Follow-up to c8d8f08 curl#22023 Follow-up to e95f509 curl#16852
In some configurations the `write()` functions gets the
`warn_unused_result` attribute, that makes casting to `(void)`
ineffective to silence this warning. Seen with glibc, in 5 CI jobs.
The warning option appeared in GCC 4.5 and comes enabled by default.
```
tests/server/util.c:329:5: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
329 | write(STDERR_FILENO, msg, sizeof(msg) - 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Ref: https://github.com/curl/curl/actions/runs/27548333990/job/81427544632
Refs:
#22023 (comment)
https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wunused-result
https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Common-Attributes.html#index-warn_005funused_005fresult
https://stackoverflow.com/questions/40576003/ignoring-warning-wunused-result
Follow-up to c8d8f08 #22023
Follow-up to e95f509 #16852
Closes #22034
No description provided.