-dip1000 and non-scope variables
Dukc
ajieskola at gmail.com
Thu Feb 18 14:33:19 UTC 2021
On Thursday, 18 February 2021 at 10:05:52 UTC, RazvanN wrote::
>
> class MinPointerRecorder
> {
> int* minPrice;
> void update(ref int price) @safe
> {
> minPrice = &price; /* Should not compile. */
> }
> }
> [snip]
> Does anyone know what exactly is the intended behavior?
> Unfortunately both the spec and the DIP [2] do not explicitly
> mention this cases.
>
That member function itself can compile, no problem. But -dip1000
should prevent calling it with a local argument:
```
@safe void foo(int arg)
{ auto mpr= new MinPointRecorder();
mpr.update(*new int); //okay
mpr.update(arg); //won't do - escaping reference to local
variable
}
```
Or that's my understanding at least.
More information about the Digitalmars-d
mailing list