digitalmars.D.bugs - [Issue 1765] New: foreach scope does not call destructor
- d-bugmail puremagic.com (52/52) Jan 02 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1765
- d-bugmail puremagic.com (12/12) Sep 10 2009 http://d.puremagic.com/issues/show_bug.cgi?id=1765
http://d.puremagic.com/issues/show_bug.cgi?id=1765 Summary: foreach scope does not call destructor Product: D Version: 2.008 Platform: All OS/Version: All Status: NEW Keywords: wrong-code Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: gide nwawudu.com Foreach statement (without braces '{}') and scoping objects, prevents the call to the object's destructor. The code below outlines the problem. Code ---- module main; import std.stdio; class MyClass { public: this() { writefln("Constructor"); } ~this() { writefln("Destructor"); } private: int myNumber; }; int main() { writefln("1 - Start: OK dtor called"); foreach (a; new int[1]) { scope x = new MyClass; } writefln("1 - End: OK dtor called\n"); writefln("2 - Start: dtor NOT called"); foreach (a; new int[1]) scope x = new MyClass; writefln("2 - End: dtor NOT called\n"); return 0; }; Output ------ 1 - Start: OK dtor called Constructor Destructor 1 - End: OK dtor called 2 - Start: dtor NOT called Constructor 2 - End: dtor NOT called --
Jan 02 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1765 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |clugdbug yahoo.com.au Resolution| |FIXED This was fixed in DMD2.032 (probably a side-effect of the fix for bug 2925). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 10 2009