On Friday, April 29, 2016 at 8:04:46 PM UTC+10, Nicholas Nethercote wrote:
> On Fri, Apr 29, 2016 at 10:25 AM, Nicholas Nethercote
> <n.neth...@gmail.com> wrote:
> >
> > I just landed on inbound the patches in bug 1267550, which renamed
> > MOZ_WARN_UNUSED_RESULT as MOZ_MUST_USE.
> >
> > A shorter name was in order because it's an attribute that is already
> > used widely, and should be used even more, because it catches real
> > problems. In fact, any function that is fallible and returns a
> > non-pointer value (usually a bool or nsresult) is a candidate for a
> > MOZ_MUST_USE annotation.
> 
> I've created bug 1268766 as a meta-bug for tracking the addition of
> more uses of MOZ_MUST_USE. I've started working on this in a few
> places -- and already found a bunch of missing failure checks -- but
> we have more than enough code for the task to be shared around, if
> anybody is interested.
> 
> Also note that we have another attribute called MOZ_MUST_USE_TYPE,
> which can be applied to a type, and then any function that returns
> that type will need to be checked. (In other words, it implicitly adds
> MOZ_MUST_USE to any function that returns that type.) Bug 1209780 is a
> nice example of its use. (Note that it used to be called MOZ_MUST_USE,
> and was renamed MOZ_MUST_USE_TYPE to allow MOZ_WARN_UNUSED_RESULT to
> be renamed as MOZ_MUST_USE.) However, it only works in static analysis
> builds, whereas MOZ_MUST_USE also works in GCC and clang, so although
> it clutters up code less, it also results in less immediate error
> messages.
> 
> Nick

Thank you for that.


Now, for maximum defensiveness, shouldn't we go even further?

How about: Make 'MOZ_MUST_USE' implicit for all functions/methods (except void 
of course, probably methods returning T&, and maybe more as they come up).
When a result is not needed somewhere, use the 'Unused << foo()' idiom.
And if a function's return is really not important, then mark it with 
MOZ_MAY_IGNORE_RESULT (or similar).

I admit I haven't thoroughly thought through all the implications, maybe it's 
just too hard to put in place and then fix all the errors that would 
immediately pop up, but it'd be interesting to try I think. Or dispiriting.


In the meantime, would you have some suggestions/guidelines as to where we 
should add MOZ_MUST_USE?
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to