[Bug c/66425] (void) cast doesn't suppress __attribute__((warn_unused_result))
rusty at rustcorp dot com.au
gcc-bugzilla@gcc.gnu.org
Tue Jul 23 23:45:09 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
--- Comment #83 from rusty at rustcorp dot com.au ---
> Then they shouldn't use warn_unused_result! The documentation of that is very very clear: both about what it does, and about what situations it is meant for. People who want something else should *use* something else!
1) In 2005 when this bug was reported, there was no alternative. There still
isn't (for C, not C++).
2) Despite our best intentions, people use things in unintended ways, and it
becomes something else. I have both sympathy for your viewpoint, and for users
caught in the middle.
Documentation says:
"This is useful for functions where not checking the result is either a
security problem or always a bug, such as ‘realloc’."
If we added __attribute__((nodiscard)) a-la C++, then this would be a good
place to recommend it for cases where you *almost* always want to consider the
result.
> The existing w_u_r is very obviously very useful though, as it is, and should not be weakened in any way
It is *so* useful it gets used anywhere you want to caution the user that they
*probably* meant to check the result. But it does not follow that making
(void) remove the warning vs a GNULib macro would not make it notably less
useful.
More information about the Gcc-bugs
mailing list