On Monday 2014-12-22 16:10 -0500, Jeff Muizelaar wrote:
> We were talking about this problem and it was a bunch of work to figure out 
> the conclusion so I decided to write a summary:
> 
> Replacing already_AddRefed with nsRefPtr causes allows two new things:
> 
> nsRefPtr<T> getT();
> 
> 1. T* p = getT(); // this is unsafe because the destructor runs immediately 
> and p is left dangling
> 2. foo(getT()); // this is safe
> 
> Possible solutions would be to:
>  - remove implicit conversions to T*
>  - add operator T* explicit and operator T* && = delete // this will be 
> available in GCC 4.8.1 and MSVC 2014 Nov CTP

I think removing implicit conversions to T* will make a lot of code
in the tree uglier (".get()" everywhere).  That might, in turn,
encourage people to do worse things to avoid having to write .get()
everywhere; it's worth thinking about what those things will be.

(I think it's also worth thinking about the *massive* number of
callsites that will need to be fixed if we remove implicit
conversion to T*.)

I'd also like to keep nsRefPtr and nsCOMPtr consistent with each
other in this regard, to avoid people having to learn additional
patterns.  (And, on that subject, I think development practice in
MFBT has been too readily adding new and different things instead of
moving the existing things from XPCOM into MFBT and then improving
them incrementally.)

-David

-- 
𝄞   L. David Baron                         http://dbaron.org/   𝄂
𝄢   Mozilla                          https://www.mozilla.org/   𝄂
             Before I built a wall I'd ask to know
             What I was walling in or walling out,
             And to whom I was like to give offense.
               - Robert Frost, Mending Wall (1914)

Attachment: signature.asc
Description: Digital signature

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to