Bug 4712 – Issue of destructor for temporary instance of structs

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-08-22T06:29:00Z
Last change time
2010-11-14T09:59:35Z
Keywords
wrong-code
Assigned to
nobody
Creator
zan77137

Comments

Comment #0 by zan77137 — 2010-08-22T06:29:06Z
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"); }
Comment #1 by clugdbug — 2010-08-22T12:43:53Z
Is this the same as bug 3516? The fact that turning on the optimiser is not mentioned there, and may indicate it's a different bug. But they seem to be closely related.
Comment #2 by zan77137 — 2010-11-14T09:59:35Z
This issue is already fixed. (Because it was fixed before I knew it, I don't know revision clearly.)