How could I make it compile error?

I did write

RefPtr<Foo> xxx = yyy;
xxx.forget();

It is ok for compiling on my Mac.

The comment [1] said " Makes it a compile time error to not use the return
value of a function which has this type", but how do I make the clang
format take effect?

BTW, if you want to ignore the return value, you can use the special
version of Unused [2], but it will leak if you don't manually delete the
pointer.
[1]
http://searchfox.org/mozilla-central/rev/48ea452803907f2575d81021e8678634e8067fc2/mfbt/Attributes.h#519-521
[2]
http://searchfox.org/mozilla-central/rev/48ea452803907f2575d81021e8678634e8067fc2/mfbt/AlreadyAddRefed.h#112-117

2017-08-24 17:31 GMT+08:00 <jyaven...@mozilla.com>:

> On Thursday, August 17, 2017 at 1:02:56 PM UTC+2, Aryeh Gregor wrote:
> > Note that in this case you cannot ignore the return value -- it must
> > be assigned to an nsCOMPtr or a RefPtr, or else it will leak.  Ideally
> > we would allow a return type of nsCOMPtr<nsIMutableArray>&&, but
> > currently I think we don't.
>
> This is not entirely correct.
>
> alreadyAddRefed<T> is marked MOZ_MUST_USE_TYPE.
>
> If you do not use the return value, it will not compile.
> _______________________________________________
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to