Note: I'm not taking a position on the language feature, just between
your two designs.

-Ekr


On Sun, Oct 11, 2015 at 5:34 AM, Eric Rescorla <e...@rtfm.com> wrote:

>
> On Sun, Oct 11, 2015 at 4:28 AM, Aryeh Gregor <a...@aryeh.name> wrote:
>
>> On Sun, Oct 11, 2015 at 2:09 PM, Aryeh Gregor <a...@aryeh.name> wrote:
>> > A new language feature could be used to solve this: allow conversion
>> > operators to behave differently based on how the variable is declared.
>> > For instance, it might convert differently if the source or
>> > destination is a local variable, global/static variable, member
>> > variable, or function parameter.  This would allow our problem to be
>> > easily solved by defining something in nsCOMPtr like:
>> >
>> >   operator T* [[parameter]]()&&;
>> >
>> > while leaving the operator deleted for non-parameters.
>>
>> Actually, you could perhaps do even better than that.  Use nsCOMPtr<T>
>> for refcounted parameters instead of T*, and then delete the T*
>> constructor for [[parameter]] nsCOMPtr<T>, and have the constructor
>> and destructor for nsCOMPtr parameters not do addref/release.  Then
>> you have the effect of bug 1194195 without having to introduce a new
>> type.  nsCOMPtr(/RefPtr) would be the type to use anywhere you want to
>> require a strong reference, and it would magically sort out the
>> addrefs/releases for you.  (Although I know a lot of people don't like
>> such magic either, so this isn't strictly superior.  But the option
>> would be available.)
>
>
> This seems far superior because it encourages people not to unbox
> pointers which seems like a good thing all other things being equal.
> (I'd actually go further, and say it's a good thing in general, but not
> everyone seems to agree....)
>
> -Ekr
>
>
>
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to