www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5172] New: ModuleInfo's flags not correct WRT class static ctor/dtor when compiled with -lib

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 puremagic.com
        ReportedBy: schveiguy yahoo.com



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: -------
Nov 05 2010