On 08/02/2015 02:34 PM, Hubert Figuière wrote:
On 02/08/15 07:17 AM, smaug wrote:
Probably we should generally avoid using constructor directly for
those cases. Instead, use helper functions like MakeUnique() or
MakeAndAddRef(), which is much safer.

MakeAndAddRef would have the same problem as MakeUnique. Doesn't really
tell what type is returned.

makeSomeRefCountedFoo(), newSomeRefCountedFoo() or
SomeRefCountedFoo::make() returning an nsRefPtr<SomeRefCountedFoo>. It
is a matter of having an enforced convention for naming them.

And when you're dealing with lifetime management issues, you really want
to know what kind of type you're playing with.

This is also part of why I'd suggest having an construction method that
will return a smart pointer - preventing the use of raw pointers. So
that there is no ambiguity in what we deal with and its ownership.


Sure,
static already_AddRefed<ClassFoo> ClassFoo::Create()
would make sense.
(or returning nsRefPtr<ClassFoo>&& ?)
But that has nothing to do with auto.
One should still see in the calling code what the type is in order to
verify lifetime management is ok.




This is probably not something trivial in our codebase.

Hub


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

Reply via email to