Bug 4622 – Module constructor is not called under some circumstances

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-08-11T11:27:00Z
Last change time
2010-08-16T11:20:41Z
Assigned to
nobody
Creator
michal.minich

Comments

Comment #0 by michal.minich — 2010-08-11T11:27:21Z
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; }
Comment #1 by sean — 2010-08-16T11:20:41Z
Fixed in druntime revision 369.