Bug 5172 – ModuleInfo's flags not correct WRT class static ctor/dtor when compiled with -lib
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-11-05T10:38:00Z
Last change time
2016-08-25T19:03:56Z
Keywords
wrong-code
Assigned to
nobody
Creator
schveiguy
Comments
Comment #0 by schveiguy — 2010-11-05T10:38:53Z
Given the following 3 modules:
mod1.d:
import mod2;
__gshared int y = 2;
shared static this()
{
y = C.x;
}
mod2.d:
import mod1;
class C
{
__gshared static int x = 1;
shared static this()
{
x = y;
}
}
myapp.d:
import mod1;
import mod2;
import std.stdio;
void main()
{
writefln("x = %d, y = %d", C.x, y);
}
----------------
Clearly there is a cyclic dependency, and x and y will be 2 or 1 depending on module ctor order.
If I compile with the following lines (on Linux):
dmd -lib -oflibmylib.a mod1.d mod2.d
dmd myapp.d -L-L. -L-lmylib
The compiler builds and myapp runs without any errors, printing x = 1, y = 1. The problem stems from the fact that the compiler does not mark mod2 as having any static ctors.
However, if I compile as:
dmd myapp.d mod1.d mod2.d
Then the compiler builds, but myapp fails with a cyclic dependency failure.
Comment #1 by schveiguy — 2016-08-25T19:03:56Z
This appears to be fixed in the latest version of the compiler, not sure when it was fixed.