ref is unsafe

David Nadlinger see at klickverbot.at
Thu Jan 3 15:06:02 PST 2013


On Thursday, 3 January 2013 at 22:50:38 UTC, Rob T wrote:
> On Thursday, 3 January 2013 at 21:56:22 UTC, David Nadlinger 
> wrote:
>> I must admit that I haven't read the rest of the thread yet, 
>> but I think the obvious and correct solution is to disallow 
>> passing locals (including non-ref parameters, which are 
>> effectively locals in D) as non-scope ref arguments.
>
> The problem with that idea, is that a ref return with no 
> arguments may call another ref return that returns something 
> that escapes the scope it was created in. If the source code is 
> not available, then there's no way for the compiler to 
> determine that this is going on.

I am not quite sure what you are trying to say. If the compiler 
never sees the source code for the functions, then codegen is 
going to be difficult. ;)

Yes, if you just see "void iPromiseNotToEscapeMyParameter(scope 
ref int a) @safe;", then there is no way to directly check that 
the function actually does not leak the parameter address. 
However, you can be sure that the compiler checked that when 
generating the code for the function.

David


More information about the Digitalmars-d mailing list