www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DIP-1000 and slice lifetimes

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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?
Dec 16 2016
next sibling parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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.
Dec 16 2016
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
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
Dec 16 2016
parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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. 😊
Dec 16 2016
parent reply Walter Bright <newshound2 digitalmars.com> writes:
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!
Dec 16 2016
parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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.
Dec 16 2016