www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10928] New: Fails to create closures that reference structs with dtor

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10928

           Summary: Fails to create closures that reference structs with
                    dtor
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dmitry.olsh gmail.com



07:58:43 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10928




07:59:13 PDT ---
Error message:
d_test.d(10): Error: variable d_test.foo.bar has scoped destruction, cannot
build closure

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10928


Joseph Rushton Wakeling <joseph.wakeling webdrake.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |joseph.wakeling webdrake.ne
                   |                            |t



2013-08-30 08:31:42 PDT ---
For reference, an "in-the-wild" example of such an error:
http://forum.dlang.org/post/mailman.445.1377370120.1719.digitalmars-d puremagic.com
http://forum.dlang.org/thread/mailman.443.1377369357.1719.digitalmars-d puremagic.com

This is a concern as it potentially blocks the ability to move forward with
necessary redesign work on random number generation in Phobos.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10928


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com




 For reference, an "in-the-wild" example of such an error:
 http://forum.dlang.org/post/mailman.445.1377370120.1719.digitalmars-d puremagic.com
 http://forum.dlang.org/thread/mailman.443.1377369357.1719.digitalmars-d puremagic.com
 
 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); } //---- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 30 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10928




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/8d50d807bed69ee9b339de81ee50f3c105ef3900
sidestep issue 10928

https://github.com/D-Programming-Language/phobos/commit/01a2bdb02e45f61ed3773d40d2aac4dadcb2a767


Sidestep issue 10928

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 01 2013