[Issue 15952] New: struct in closure is destroyed when parent function returns
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Apr 23 11:25:12 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15952
Issue ID: 15952
Summary: struct in closure is destroyed when parent function
returns
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ag0aep6g at gmail.com
Found by Ramon who posted to D.learn:
http://forum.dlang.org/post/ygqsvhyjdmigeirtwice@forum.dlang.org
----
struct S
{
int x;
~this() {x = 1;}
}
void delegate() makeDelegate()
{
auto s = S(2);
return {assert(s.x == 2); /* fails; should pass */};
}
void main()
{
auto dg = makeDelegate();
dg();
}
----
Apparently, the destructor is called when makeDelegate returns. But s is in a
closure and should be destroyed only when that closure is collected.
--
More information about the Digitalmars-d-bugs
mailing list