DIP-1000 and slice lifetimes
Nordlöw via Digitalmars-d
digitalmars-d at puremagic.com
Fri Dec 16 06:36:37 PST 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. 😊
More information about the Digitalmars-d
mailing list