DIP1000: Scoped Pointers

Walter Bright via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sat Aug 13 04:09:05 PDT 2016


On 8/13/2016 1:13 AM, Joseph Rushton Wakeling wrote:
> On Friday, 12 August 2016 at 19:37:47 UTC, Walter Bright wrote:
>> That's just what this DIP addresses.
>>
>>     struct MyWrapperStruct (T)
>>     {
>>         private T* data;
>>
>>         public this (ref T input)
>>         {
>>             this.data = &input; // error: not allowed to take address of ref
>> variable
>>         }
>>     }
>>
>> The DIP does not add ownership annotations or semantics.
>
> Unless I've misunderstood you, that doesn't address my use-case -- it outright
> bans it!

Taking the address of a ref variable has not been allowed in @safe code for a 
long time.


> The above code is unsafe only if the lifetime of `data` outlives the lifetime of
> `input`.  Surely the new scope rules should be able to distinguish the cases?
> If that's already envisioned, how would that work?

That depends on how the instance of MyWrapperStruct is allocated. How did you 
intend to allocate it?



More information about the Digitalmars-d-announce mailing list