http://d.puremagic.com/issues/show_bug.cgi?id=4712
Summary: Issue of destructor for temporary instance of structs Product: D Version: D2 Platform: Other OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: zan77...@nifty.com --- Comment #0 from SHOO <zan77...@nifty.com> 2010-08-22 06:29:06 PDT --- This code doesn't work! import std.stdio; auto func(int A = int.init)() { struct XXX { int a; ~this(){ writeln("dtor"); } } return XXX(); } void main() { writeln("start"); { auto x = func!(); } writeln("end"); } result: start dtor end object.Error: Access Violation If I remove the destructor, it runs correctly. Or I set -O switch to compiler, it runs correctly, too. Workaround for this bug is making dummy constructor: import std.stdio; auto func(int A = int.init)() { struct XXX { int a; this(int aa){ a = aa; writeln("ctor"); } ~this(){ writeln("dtor"); } } return XXX(A); } void main() { writeln("start"); { auto x = func!(); } writeln("end"); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------