Properly implement warn_unused_result checking for classes/structs.

Kaelyn Takata rikka at google.com
Wed Apr 1 16:30:33 PDT 2015


The previous implementation would copy the attribute from the class to
functions that have the class as their return type when the functions
are first declared. This proved to have two flaws:
  1) if the class is forward-declared without the attribute and a
     function or method with the class as a its return type is declared,
     and afterward the class is defined with warn_unused_result, the
     function or method would never inherit the attribute, and
  2) the check simply failed for functions and methods that are part of
     a template instantiation, regardless of whether the class with
     warn_unused_result is part of a specific instantiation or part of
     the template itself (presumably because those function/method
     declaration does not hit the same code path as a non-template one
     and so never inherits the attribute).

The new approach is to instead modify the two places where a function or
method call is checked for the warn_unused_result attribute on the decl
by extending the checks to also look for the attribute on the decl's
return type.
</commit-message>

I've unified the two locations that performed the check into a helper
method of FunctionDecl that returns true if the decl or its return type
have the warn_unused_result attribute, except if only the return type has
the attribute and the decl is a member of the return type (which avoids
spurious messages on e.g. assignment operators).

Cheers,
Kaelyn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150401/08be1c9c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-class-warn_unused_result.patch
Type: text/x-patch
Size: 5914 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150401/08be1c9c/attachment.bin>


More information about the cfe-commits mailing list