[PATCH] D17043: Check that the result of a library call w/o side effects is used

Joerg Sonnenberger via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 10 17:05:58 PST 2016


On Wed, Feb 10, 2016 at 04:21:02PM +0000, Alexander Kornienko via cfe-commits wrote:
> alexfh added a comment.
> 
> Thank you for working on this check!
> 
> I'd like to note that there is a library-side way to mitigate this
> issue using the `[[clang::warn_unused_result]]` attribute on
> `vector::empty()` and similar methods:

I'm not a big fan of this. Those calls are by the very definition
harmless, so they aggrevate the existing problem of stupid annotation.
The original intention of this attribute was to flag cases of side
effects where ignoring the the result is a definite bug. Consider
calling malloc or realloc and throwing away the result -- that never
makes sense. Then GNU came along and starting to annotate various libc
functions including most of the stdio family. Guess what, standard
streams have a (sticky) error flag, exactly so that you don't have check
every single call. Congratulation, people are just starting to ignore
the warnings now. Fast forward and we have this suggestion...

Joerg


More information about the cfe-commits mailing list