[Bug c/94389] __attribute__((warn_unused_result)) will warn if the result is discarded as an optimisation
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 30 14:16:58 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94389
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Compared to [[nodiscard]], warn_unused_result attempts to force users harder
not to ignore the return value. So, it doesn't allow just (void) cast to shut
up the warning, and this foo () ? 0 : 0 or 0 * foo () is similar obfuscation to
ignore the result when whomever that added the warn_unused_result attribute
wanted users not to do that.
So, use [[nodiscard]] instead of you want less aggressive checking, or change
your code, like O_TEXT != 0 ? text_mode () ? O_TEXT : 0 : 0 where you wouldn't
even call the function if you want to ignore the return value.
More information about the Gcc-bugs
mailing list