[Dlang-internal] DIP1000 discussion and testing
Walter Bright via Dlang-internal
dlang-internal at puremagic.com
Sat Dec 17 22:29:32 PST 2016
On 12/17/2016 7:38 AM, Mathias Lang wrote:
> void main () @safe
> {
> int[] a = escape();
> }
>
> int[] escape () @safe
> {
> Foo f;
> return f.foo;
> }
>
> struct Foo
> {
> int[10] v;
> int[] foo () return @safe { return this.v; }
> }
I've said it's all about pointers and addresses. So let's remove the
abstractions, and rewrite it in the equivalent pointers and addresses form:
```
void main () @safe
{
int* a = escape();
}
int* escape () @safe
{
int f;
return foo(f); // Error: escaping reference to local variable f
}
int* foo (return ref int i) @safe { return &i; }
```
and indeed it does fail to compile. So the bug in the compiler is failing to
recognize the abstract version of the pointers and addresses logic.
More information about the Dlang-internal
mailing list