[Issue 5172] New: ModuleInfo's flags not correct WRT class static ctor/dtor when compiled with -lib
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 5 10:39:52 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5172
Summary: ModuleInfo's flags not correct WRT class static
ctor/dtor when compiled with -lib
Product: D
Version: D2
Platform: Other
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: schveiguy at yahoo.com
--- Comment #0 from Steven Schveighoffer <schveiguy at yahoo.com> 2010-11-05 10:38:53 PDT ---
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.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list