Bug 10928 – Fails to create closures that reference structs with dtor
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-30T07:58:00Z
Last change time
2014-08-10T12:54:45Z
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2013-08-30T07:58:43Z
To make example real simple:
struct D{
int x;
~this()
{
}
}
void foo(D bar)
{
(){ bar.x++; }();
}
void main()
{
foo(D.init);
}
Note that even though there is no need for allocating closure at all.
Compiler should deal with such cases by tiying the lifetime of dtor-able variables to that of a closure if one is indeed required.
This is critical as std.array.array and other functions started using internal lambdas for trusted blocks making use of any RefCounted range impossible.
(In reply to comment #2)
> For reference, an "in-the-wild" example of such an error:
> http://forum.dlang.org/post/[email protected]
> http://forum.dlang.org/thread/[email protected]
>
> This is a concern as it potentially blocks the ability to move forward with
> necessary redesign work on random number generation in Phobos.
Currently, a *workaround* is to avoid lambdas in favor of named:
//----
struct D
{
int x;
~this()
{
}
}
void foo(D bar)
{
void do_it(){ bar.x++; }
do_it();
}
void main()
{
foo(D.init);
}
//----
Comment #4 by github-bugzilla — 2013-09-01T01:13:48Z