On Sun, Jul 21, 2013 at 10:39 PM, Justin Lebar <justin.le...@gmail.com>wrote:
> AIUI the new constructor would be something like > > nsRefPtr<T>(nsRefPtr<T>&& aOther) > > where "&&" means "r-value", which means "temporary", so "moveable". > Yes, this is why you want to be careful when returning them. The rules should be more conservative here than returning lvalue references. > But I'm not totally sure about being able to return nsRefPtr. > > Right now, if I do > > already_AddRefed<T> GetFoo(); > Foo* foo = GetFoo(); > > that's a compile error. In order to leak the reference, I'd have to > do foo = GetFoo().forget();, which is relatively easy for reviewers to > catch. > > But if we return nsRefPtr, then if I have > > nsRefPtr<Foo> GetFoo(); > Foo* = GetFoo(); > > that compiles fine (I think?) because nsRefPtr<T> has an implicit > conversion to T*. I'd wager that this is probably pretty hard for > reviewers to catch; at least, I don't have confidence I'd catch this > mistake. > > Maybe there's a way to delete the nsRefPtr<T> conversion to T* if the > nsRefPtr is an r-value. > It seems really dangerous that there is an implicit conversion from a strong ref ptr to a weak pointer. With C++11, you can thankfully require this conversion to be explicit which should alleviate your concern. > > On Sun, Jul 21, 2013 at 9:08 PM, Robert O'Callahan <rob...@ocallahan.org> > wrote: > > On Mon, Jul 22, 2013 at 3:58 PM, L. David Baron <dba...@dbaron.org> > wrote: > > > >> Is the idea here that nsRefPtr/nsCOMPtr/etc. would have move > >> constructors, and we'd just return them, and the move constructors > >> plus return value optimizations would take care of avoiding excess > >> reference counting? > This has been my experience with RefPtrs and C++11 though I have not used it in code as performance critical as Gecko. I have built a typesafe RefPtr class with I think very similar semantics and requirements to Gecko's so I think you will be able to do the same. -Rob _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform