April 19, 2019 Re: Nasty corner case behaviour | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky (Abscissa) | On Thu, Apr 18, 2019 at 11:05:10PM -0400, Nick Sabalausky (Abscissa) via Digitalmars-d wrote: > On 4/18/19 1:01 AM, H. S. Teoh wrote: > > Got bitten by this today: > > > > Yeeouch! Bugzilla issue #? Just filed a new bug: https://issues.dlang.org/show_bug.cgi?id=19812 T -- This is not a sentence. |
April 19, 2019 Re: Nasty corner case behaviour | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suleyman | On Fri, Apr 19, 2019 at 10:17:08PM +0000, Suleyman via Digitalmars-d wrote: > On Thursday, 18 April 2019 at 05:01:17 UTC, H. S. Teoh wrote: > > ... > > Sneaky enough. > The problem is the value copy semantics of S which results in an > address to a dead stack frame being saved. > If you make it a ref parameter the issue goes away. [...] Using ref solves it for this specific case, but will still exhibit the same problem if the struct referenced by the ref is a temporary due to other factors. E.g., if you pass the struct to a function that then returns map!(S.method) back to the caller, then the ref will still be referencing a temporary that goes out of scope while the lambda still holds the reference. The underlying problem is that the lambda closes over a variable whose lifetime is not guaranteed to be at least the lifetime of the lambda. It's exactly this sort of scoping issues that -dip1000 is supposed to prevent, but it seems somehow this case was missed. T -- IBM = I'll Buy Microsoft! |
Copyright © 1999-2021 by the D Language Foundation