<div dir="ltr">After a bit of internal testing and discussion, I've updated the patch to not look through pointers and references when checking if the return type of a function has the warn_unused_result. This fixes a lot of bogus warnings from functions like std::copy which return an iterator but for which the return value doesn't matter, when the iterator is defined as a raw pointer. The core idea behind the change is that a pointer or reference return type don't imply a transfer of ownership of the underlying object in a way that suggests the contents of the object should be accessed before the object goes out of scope.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 2, 2015 at 7:20 AM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">LGTM!<br>
<br>
~Aaron<br>
<div><div class="h5"><br>
On Wed, Apr 1, 2015 at 7:30 PM, Kaelyn Takata <<a href="mailto:rikka@google.com">rikka@google.com</a>> wrote:<br>
> The previous implementation would copy the attribute from the class to<br>
> functions that have the class as their return type when the functions<br>
> are first declared. This proved to have two flaws:<br>
>   1) if the class is forward-declared without the attribute and a<br>
>      function or method with the class as a its return type is declared,<br>
>      and afterward the class is defined with warn_unused_result, the<br>
>      function or method would never inherit the attribute, and<br>
>   2) the check simply failed for functions and methods that are part of<br>
>      a template instantiation, regardless of whether the class with<br>
>      warn_unused_result is part of a specific instantiation or part of<br>
>      the template itself (presumably because those function/method<br>
>      declaration does not hit the same code path as a non-template one<br>
>      and so never inherits the attribute).<br>
><br>
> The new approach is to instead modify the two places where a function or<br>
> method call is checked for the warn_unused_result attribute on the decl<br>
> by extending the checks to also look for the attribute on the decl's<br>
> return type.<br>
> </commit-message><br>
><br>
> I've unified the two locations that performed the check into a helper method<br>
> of FunctionDecl that returns true if the decl or its return type have the<br>
> warn_unused_result attribute, except if only the return type has the<br>
> attribute and the decl is a member of the return type (which avoids spurious<br>
> messages on e.g. assignment operators).<br>
><br>
> Cheers,<br>
> Kaelyn<br>
><br>
</div></div>> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
><br>
</blockquote></div><br></div>