static array internal & dangling reference

Picaud Vincent via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 13 22:19:25 PST 2016


On Monday, 14 November 2016 at 06:10:38 UTC, Jonathan M Davis 
wrote:


> I would have hoped that it would have complained about the 
> first one. I don't know why it isn't. It definitely results in 
> having a pointer to memory that should no longer be referenced.

Yes I would have hoped too, because it has the unfortunate 
consequence that we can not rely 100% that there is no dangling 
pointer even if valgrind said OK.

> Regardless, there's no question that returning a dynamic array 
> which is a slice of a static array is not something that is 
> valid to do when that static array is a local variable. 
> Valgrind just isn't managing to catch it in this case, 
> unfortunately.

I do agree, this is not a construct to use, I only have done this 
for testing purpose to see how D reacts.

Vincent



More information about the Digitalmars-d-learn mailing list