Repository navigation
tests: Suppress an unused-result warning - #6655
Conversation
The warning seems to happen with GCC 11 but not with GCC 13 or newer. A simple void cast still leaves the warning enabled due to a bug or intentional choice in GCC [1], so it is assigned to a variable first and then void-ed. [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
| return 1; | ||
| write(fd, msg, sizeof(msg) - 1); | ||
| ssize_t ret = write(fd, msg, sizeof(msg) - 1); | ||
| (void)ret; |
There was a problem hiding this comment.
If we expect this to be a "can't happen" then perhaps better as something like
if (write(fd, msg, sizeof(msg) - 1) != sizeof(msg) - 1)
abort();Or if it's intentionally ignored, the pattern I've often used is
if (write(fd, msg, sizeof(msg) - 1) < 0)
{
/* intentionally ignored */
}There was a problem hiding this comment.
it's being intentionally ignored, yes, is that clearer though? to me casting it seems explicit enough or are you saying to avoid the gcc issue?
There was a problem hiding this comment.
We don't have any intentionally ignored comment in the code base, we do however often use (void) funcall () to ignore the result, which would be my preference because then we don't need to declare a useless variable.
There was a problem hiding this comment.
Putting it on the write() directly doesn't suppress it, it's what the GCC issue is about.
There was a problem hiding this comment.
Sorry, missed that. Yeah, all solutions here are not great then. Could also add a ignore_unused_result macro. I'll merge any of the solutions, just let me know which one you decided on.
There was a problem hiding this comment.
imo, the current one is fine, and simpler. doing anything to suppress here would be a workaround to the gcc issue.
The warning seems to happen with GCC 11 but not with GCC 13 or newer.
A simple void cast still leaves the warning enabled due to a bug or intentional choice in GCC 1, so it is assigned to a variable first and then void-ed.
https://github.com/flatpak/flatpak/actions/runs/25602255382/job/75158068690#step:6:188