This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Disabling warn_unused_result warnings on a case-by-case basis
- From: Florian Weimer <fweimer at redhat dot com>
- To: "gcc at gnu dot org" <gcc at gnu dot org>
- Date: Tue, 14 Jun 2016 11:32:29 +0200
- Subject: Disabling warn_unused_result warnings on a case-by-case basis
- Authentication-results: sourceware.org; auth=none
A long time ago, GCC decided that warn_unused_result warnings should
*not* be silenced by casting to void, as in:
(void) write (STDOUT_FILENO, message, strlen (message));
Apparently, programmers have figured out to use this idiom as a replacement:
if (write (STDOUT_FILENO, message, strlen (message))) { }
I'm not sure if this is an improvement. The (void) idiom seems to make
the programmer intention more explicit.
Maybe it's time to reconsider and suppress the warning for casts to
(void), too?
Thanks,
Florian