[Bug c/66425] (void) cast doesn't suppress __attribute__((warn_unused_result))

lucas.de.marchi at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Jun 11 06:49:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

Lucas De Marchi <lucas.de.marchi at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lucas.de.marchi at gmail dot com

--- Comment #10 from Lucas De Marchi <lucas.de.marchi at gmail dot com> ---
(In reply to Andrew Pinski from comment #7)
> Again this has nothing to do with other lints, this attribute was designed
> so you can't ignore the return value.  And most lints/static analysis tools
> will also look to see if you not really ignoring the return value in that
> you use it in an error case fashion.  casting to void does not always cause
> (and really should not cause) static analysis to ignore what you did was
> broken for the API.  It is not GCC's fault people are starting to misuse
> this attribute; you should write into those projects instead saying they are
> misunderstanding the attribute is being used incorrectly.  I bet some of
> them, really don't want a warning even with a cast to void.

You are ignoring the fact that the places in which the attribute is put is
often out of control for those using that interface.  This means they can't
really remove the attribute or also that the attribute may make sense in MOST
of the cases but not in that particular one.

Casting to void is nowadays the de facto standard to say "I really know what
I'm doing and I don't care about the return value *here*".  This is way better
then letting each project invent their all workaround macros and even risk
doing the wrong thing like the assert you pointed out as wrong.

So maybe after 10 years it's time to revisit that decision?  It's not that the
behavior of when warnings are emitted are really set in stone and never
changed. It pretty much did all this time and we kept adapting to it.

If just changing the behavior is not acceptable then maybe splitting the
-Wunused-result to let people ignore this particular case of cast to void as
suggested would be good.

The gcc vs clang vs linters debate and who invented the attribute don't belong
to this discussion. It's better to discuss why we can't let the attribute be
actually useful by letting the users to turn it off when they know what they
are doing.



More information about the Gcc-bugs mailing list