July 26, 2017 scope pointers in @safe code | ||||
---|---|---|---|---|
| ||||
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 |
July 26, 2017 Re: scope pointers in @safe code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shachar Shemesh | On Wednesday, 26 July 2017 at 08:20:42 UTC, Shachar Shemesh wrote:
> 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
compile with -dip1000
|
Copyright © 1999-2021 by the D Language Foundation