This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/66425] (void) cast doesn't suppress __attribute__((warn_unused_result))
- From: "filbranden at google dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 11 Jun 2015 05:55:38 +0000
- Subject: [Bug c/66425] (void) cast doesn't suppress __attribute__((warn_unused_result))
- Auto-submitted: auto-generated
- References: <bug-66425-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
--- Comment #6 from Filipe Brandenburger <filbranden at google dot com> ---
Then please explain to me how this:
(void) foo();
is any worse than this:
int ignored __attribute__((unused));
ignored = foo();
/* do nothing with ignored here */
You can force me to assign the return value to something, but you can't really
force me to do something useful with it...
In the cases above, I think the former is a much more clear way to express my
intent to ignore that value, I'm telling the compiler "yeah, I know, I'm
supposed to use this value, but in this particular case I really know what I'm
doing so please bear with me here."
The -Wunused-result warnings would be a lot more useful (or, actually, just
useful) if I was able to whitelist the places where I want to ignore the
values, since right now my only practical choice is to disable it completely
with -Wno-unused-result.
This is an example of a *real* problem that would have been caught by this
warning:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509#c28
And it's not just LLVM... Other linters and static analysis tools seem to agree
that a (void) cast is an explicit indication that the coder meant to ignore
those results, so why would gcc want to be the one exception here?
Thanks!
Filipe