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.) _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform