[Issue 9795] New: cast fails for C's forward referenced structure pointer

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 23 09:59:25 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9795

           Summary: cast fails for C's forward referenced structure
                    pointer
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: kodlists-dlang at yahoo.com


--- Comment #0 from Sarath Kumar Kodali <kodlists-dlang at yahoo.com> 2013-03-23 09:59:23 PDT ---
With DMD32 D Compiler v2.062,

$ cat libA.d
module libA;

extern (C)
{
        struct Opaque;  // forward reference
        Opaque* getObject();
}

$ cat libB.d
module libB;

extern (C)
{
        struct Opaque;  // forward reference
        void doAction(Opaque *);
}

$ cat bug.d
import libA, libB;

int main(string[] args)
{
        auto opaque = libA.getObject();
        libB.doAction(cast(libB.Opaque *)opaque);
        return 0;
}

$ rdmd bug.dlibB.d(5): Error: struct libB.Opaque unknown size
libB.d(5): Error: struct libB.Opaque no size yet for forward reference
libB.d(5): Error: struct libB.Opaque unknown size
libB.d(5): Error: struct libB.Opaque no size yet for forward reference
libA.d(5): Error: struct libA.Opaque unknown size
libA.d(5): Error: struct libA.Opaque no size yet for forward reference
Failed: 'dmd' '-v' '-o-' 'bug.d' '-I.'
$

If we declare Opaque in a separate file and import it in libA and libB, then
there is no compiler error. Also if we remove the cast in bug.d, the error
message would be:

bug.d(6): Error: function libB.doAction (Opaque*) is not callable using
argument types (Opaque*)
bug.d(6): Error: cannot implicitly convert expression (opaque) of type Opaque*
to Opaque*

The compiler should have qualified Opaque so that it is easier to understand
that it cannot convert libA.Opaque* to libB.Opaque*

-- 
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