DIP-1000 and slice lifetimes
    Walter Bright via Digitalmars-d 
    digitalmars-d at puremagic.com
       
    Fri Dec 16 05:30:47 PST 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
    
    
More information about the Digitalmars-d
mailing list