[Issue 10409] New: dtor / destructor not called for (rvalue) struct used in opApply

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 18 16:09:27 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10409

           Summary: dtor / destructor not called for (rvalue) struct used
                    in opApply
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: Marco.Leise at gmx.de


--- Comment #0 from Marco Leise <Marco.Leise at gmx.de> 2013-06-18 16:09:26 PDT ---
This code

--- 8< ---------------

import core.stdc.stdio;

struct DestroyMe
{
    ~this() { printf("~this() called\n"); }

    int opApply(in int delegate(int item) dg)
    {
        throw new Exception("Here we go!");
    }
}

void main()
{
    printf("Version with no dtor call:\n");
    try {
        foreach (item; DestroyMe()) {}
    } catch {}
    printf("Version with dtor call:\n");
    try {
        auto lvalue = DestroyMe();
        foreach (item; lvalue) {}
    } catch {}
}

--- >8 --------------

prints:
Version with no dtor call:
Version with dtor call:
~this() called

So the dtor call gets missed when the struct's scope is inside the foreach
header. There is another open bug about struct destructors not being called on
out parameters:
http://d.puremagic.com/issues/show_bug.cgi?id=6186

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


More information about the Digitalmars-d-bugs mailing list