[Issue 21745] Closure created in struct constructor passed to class constructor refers to expired stack frame

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 25 10:34:29 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21745

--- Comment #10 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to Walter Bright from comment #9)

Thanks for the thourough explanation

> 
> dmd test -dip1000 yields:
> 
>  test.d(19): Error: reference to local `this` assigned to non-scope
> parameter `dg` calling test3.Bar.this
> 
> This kind of subtle stack corruption problem is what DIP1000 is designed to
> detect.
> 

The error is super weird. As a user who does not understand the inner-mechanics
of how closures are allocated, this error tells me nothing. How is `this` of
type `Foo` assigned to a delegate? What am I supposed to do as a user to get
rid of this error?

> I recommend:
> 
> 1. redesign the code so that Foo is allocated on the heap, or at least in a
> location that outlives the pointer to it in a delegate
> 
> 2. consider using @safe and -dip1000

--


More information about the Digitalmars-d-bugs mailing list