Bug 6364 – Static struct's destructor called on exit of function

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-22T22:08:00Z
Last change time
2012-01-08T15:03:03Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2011-07-22T22:08:18Z
import std.stdio; void main() { test(); test(); } struct Foo { int state = 1; ~this() { state = 0; } } void test() { static Foo foo; writeln(foo.state); } Prints: 1 0
Comment #1 by andrej.mitrovich — 2012-01-04T07:07:56Z
(In reply to comment #0) To clarify: It should print 1 both times. I think the dtor should run on app exit, since it's a static variable.
Comment #2 by k.hara.pg — 2012-01-06T08:27:30Z
https://github.com/D-Programming-Language/dmd/pull/612 NOTE: This patch does not fix "dtor is never called on global variable" problem (it is filed as bug 6437). So after the patch applied, foo's dtor would never be called.
Comment #3 by andrej.mitrovich — 2012-01-06T09:24:52Z
(In reply to comment #2) > https://github.com/D-Programming-Language/dmd/pull/612 > > NOTE: This patch does not fix "dtor is never called on global variable" problem > (it is filed as bug 6437). > So after the patch applied, foo's dtor would never be called. Yeah they're two different bugs, I guess. Thanks for fixing this one though!
Comment #4 by bugzilla — 2012-01-08T15:03:03Z