scope pointers in @safe code

Shachar Shemesh via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 26 01:20:42 PDT 2017


void fn(scope int* var) @safe {
     (*var)++;
}

void fn2() @safe {
     int a;

     fn(&a);
}

The above program does not compile:
d.d(8): Error: cannot take address of local a in @safe function fn2

I propose that the scope keyword be activated to mean "I do not pass the 
pointer you gave me out of the function", which would make this code 
compile (as it should, as it is not doing anything unsafe).

Shachar


More information about the Digitalmars-d mailing list