[webkit-dev] RefPtr/PassRefPtr Question

David Levin levin at google.com
Wed Aug 31 15:28:48 PDT 2011

Any of these should work:

RefPtr<T> myLocal;
bool success = myFunc(myLocal);

Uses  template<typename U> PassRefPtr(const RefPtr<U>&);


RefPtr<T> myLocal;
bool success = myFunc(myLocal.release());


RefPtr<T> myLocal;
bool success = myFunc(myLocal.get());

Uses PassRefPtr(T* ptr)

The second form is prefered if you won't be using myLocal again in the
function. I would use the first form if you are using myLocal again.


On Wed, Aug 31, 2011 at 3:16 PM, David Hyatt <hyatt at apple.com> wrote:

> I am getting complaints from check-webkit-style in a bug regarding
> PassRefPtr/RefPtr usage, and I can't figure out what I should be doing. It
> yells at me no matter what I try.
> The scenario I have is that a function is wanting to transfer ownership but
> it's not doing it via a return value. Instead it is filling in a reference
> parameter.
> The current code looks like this:
> Caller:
> RefPtr<T> myLocal;
> bool success = myFunc(myLocal);
> With the function being:
> bool myFunc(RefPtr<T>& result);
> With this setup though, I get yelled at by the style checker and it tells
> me that the parameter should be a PassRefPtr. However I don't get how I can
> do that, since then I have:
> PassRefPtr<T> myLocal;
> and I get yelled at for making a PassRefPtr local variable.
> What's the right way to write this code such that it will pass? Is this
> just a flaw in the style checker? It sure seems like a RefPtr<T> reference
> parameter should be allowed...
> dave
> (hyatt at apple.com)
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20110831/95a945b7/attachment.html>

More information about the webkit-dev mailing list