Skip to content

tests: Suppress an unused-result warning - #6655

Merged
swick merged 1 commit into
mainfrom
bbhtt/fix-warning
May 27, 2026
Merged

swick merged 1 commit into
mainfrom
bbhtt/fix-warning

Conversation

@bbhtt

@bbhtt bbhtt commented May 12, 2026 •

Copy link
Copy Markdown
Collaborator

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

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;

@smcv smcv May 12, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 */
      }

@bbhtt bbhtt May 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting it on the write() directly doesn't suppress it, it's what the GCC issue is about.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bbhtt bbhtt May 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, the current one is fine, and simpler. doing anything to suppress here would be a workaround to the gcc issue.

@swick
swick added this pull request to the merge queue May 27, 2026
Merged via the queue into main with commit a38377e May 27, 2026
16 of 17 checks passed
@swick
swick deleted the bbhtt/fix-warning branch May 27, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants