DIP1000: Scoped Pointers

Patrick Schluter via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Aug 16 09:26:29 PDT 2016


On Monday, 15 August 2016 at 21:25:22 UTC, Walter Bright wrote:
> On 8/15/2016 6:54 AM, Rory McGuire via Digitalmars-d-announce 
> wrote:
>> okay nice, so that code would not compile but code such as:
>> void test() {
>> scope rnd  = new Rnd; // reference semantic and stack allocated
>> auto rnd2 = rnd;
>>         some_sneaky_function_that_saves_global_state(rnd);
>> }
>> would still not be checked. And would crash inexplicably at 
>> the point the global
>> was accessed?
>
> A local variable initialized with a scoped value will have 
> 'scope' inferred for it.

What happens in that case ?

void test() {
scope rnd  = new Rnd; // reference semantic and stack allocated
Rnd rnd2;
  rnd2 = rnd;
          some_sneaky_function_that_saves_global_state(rnd);
}

or is that not even possible ? (sorry I'm still a noob in D).


More information about the Digitalmars-d-announce mailing list