Thread overview
DIP-1000 and slice lifetimes
Dec 16, 2016
Nordlöw
Dec 16, 2016
Nordlöw
Dec 16, 2016
Walter Bright
Dec 16, 2016
Nordlöw
Dec 16, 2016
Walter Bright
Dec 16, 2016
Nordlöw
December 16, 2016
Will DIP-1000 correctly forbid code such as

    int[] xs;
    {
        int[3] x = [1, 2, 3];
        xs = x[]; // leaks dangling pointer `xs.ptr` to enclosing scope
    }
    xs[] = 0; // undefined behaviour

from compiling?
December 16, 2016
On Friday, 16 December 2016 at 12:37:56 UTC, Nordlöw wrote:
> Will DIP-1000 correctly forbid code such as...

If code reside in a @safe function, that is.
December 16, 2016
On 12/16/2016 4:37 AM, Nordlöw wrote:
> Will DIP-1000 correctly forbid code such as
>
>     int[] xs;
>     {
>         int[3] x = [1, 2, 3];
>         xs = x[]; // leaks dangling pointer `xs.ptr` to enclosing scope
>     }
>     xs[] = 0; // undefined behaviour
>
> from compiling?

----
@safe void foo()
{
    int[] xs;
    {
        int[3] x = [1, 2, 3];
        xs = x[]; // leaks dangling pointer `xs.ptr` to enclosing scope
    }
    xs[] = 0; // undefined behaviour
}
----
test.d(6): Error: address of variable x assigned to xs with longer lifetime
December 16, 2016
On Friday, 16 December 2016 at 13:30:47 UTC, Walter Bright wrote:
> On 12/16/2016 4:37 AM, Nordlöw wrote:
>> Will DIP-1000 correctly forbid code such as
>>
>>     int[] xs;
>>     {
>>         int[3] x = [1, 2, 3];
>>         xs = x[]; // leaks dangling pointer `xs.ptr` to enclosing scope
>>     }
>>     xs[] = 0; // undefined behaviour
>>
>> from compiling?
>
> ----
> @safe void foo()
> {
>     int[] xs;
>     {
>         int[3] x = [1, 2, 3];
>         xs = x[]; // leaks dangling pointer `xs.ptr` to enclosing scope
>     }
>     xs[] = 0; // undefined behaviour
> }
> ----
> test.d(6): Error: address of variable x assigned to xs with longer lifetime

Awesome! Your PR has been pending for quite some time. Im eagerly waiting for it to be reviewed and merged. 😊
December 16, 2016
On 12/16/2016 6:36 AM, Nordlöw wrote:
> Awesome! Your PR has been pending for quite some time. Im eagerly waiting for it
> to be reviewed and merged. 😊

So am I!
December 16, 2016
On Friday, 16 December 2016 at 16:08:02 UTC, Walter Bright wrote:
> So am I!

I wish I could help out, but I feel like I'm too unskilled in DMD internals to help out in the review.