Thread overview
[Issue 6364] New: Static struct's destructor called on exit of function
Jul 23, 2011
Andrej Mitrovic
Jan 04, 2012
Andrej Mitrovic
Jan 06, 2012
Kenji Hara
Jan 06, 2012
Andrej Mitrovic
Jan 08, 2012
Walter Bright
July 23, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6364

           Summary: Static struct's destructor called on exit of function
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-07-22 22:08:18 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 04, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6364



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-01-04 07:07:56 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6364


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, wrong-code
           Platform|Other                       |All
         OS/Version|Windows                     |All


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-01-06 08:27:30 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6364



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-01-06 09:24:52 PST ---
(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!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6364


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2012-01-08 15:03:03 PST ---
https://github.com/D-Programming-Language/dmd/commit/04e49317d79269c2ec30217562b97eaa6f9699a7

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