August 11, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4622

           Summary: Module constructor is not called under some
                    circumstances
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: michal.minich@gmail.com


--- Comment #0 from Michal Minich <michal.minich@gmail.com> 2010-08-11 11:27:21 PDT ---
Module constructor is not called when it is placed in imported module and WinMain/custom runtime initialization is used (it does not happens when ordinary "main" is used or when static this is in main module).


module hello;

import core.runtime;
import std.c.windows.windows;
import std.stdio;
import a;

extern (Windows)
int WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
    int result;

    void exceptionHandler (Throwable ex) { throw ex; }

    Runtime.initialize(&exceptionHandler);

    result = myWinMain();

    Runtime.terminate(&exceptionHandler);

    return result;
}

int main ()
{
   writeln (i1); // <-- ----- prints "1" wich is ok.

   writeln (i2); // <-------- prints "0" wich is incorrect, should be "2".

   return 1;
}


------------------------
module a;

int i1 = 1;
int i2;

static this () {

    i2 = 2;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 16, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4622


Sean Kelly <sean@invisibleduck.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |sean@invisibleduck.org
         Resolution|                            |FIXED
         OS/Version|Linux                       |Windows


--- Comment #1 from Sean Kelly <sean@invisibleduck.org> 2010-08-16 11:20:41 PDT ---
Fixed in druntime revision 369.

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