On 31/12/2012 14:44, Nick Treleaven wrote:
On 30/12/2012 22:01, Jonathan M Davis wrote:
The closest that we could get to what you suggest would be to add a new
attribute similar to nothrow but which guarantees that the function
does not
return a ref to a parameter. So, you'd have to mark your functions
that way
(e.g. with @norefparamreturn). Maybe the compiler could infer it for
templated
ones, but this attribute would basically have to work like other inferred
attributes and be marked manually in all other cases. Certainly, you
can't
have the compiler figuring it out for you in general, because D's
compilation
model allows the function being called to be compiled separately from
(and
potentially after) the function calling it.
As you suggested below that, I would have the attribute mean the
opposite, @refparamreturn. Functions that need it but don't have it can
be detected by recompiling them. The syntax could be 'in ref':
in ref int quux(ref int i);
Actually overloading 'in ref' with a different meaning on return type
from parameter (const scope) is probably a bad idea. Instead:
ref int quux(@escape ref int i);
[...]
I suppose a parameter attribute might be useful to allow passing locals
to other ref parameters which aren't returned, and as documentation.