Bug 9795 – cast fails for C's forward referenced structure pointer

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2013-03-23T09:59:00Z
Last change time
2013-10-01T19:24:03Z
Assigned to
nobody
Creator
kodlists-dlang

Comments

Comment #0 by kodlists-dlang — 2013-03-23T09:59:23Z
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*
Comment #1 by k.hara.pg — 2013-10-01T19:24:03Z
This is a dup of bug 10451. With 2.064 git-head, the OP code correctly reports link-time errors. $ dmd libA.d libB.d bug.d DMD v2.064 DEBUG OPTLINK (R) for Win32 Release 8.00.12 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html libA.obj(libA) Error 42: Symbol Undefined _getObject libA.obj(libA) Error 42: Symbol Undefined _doAction --- errorlevel 2 *** This issue has been marked as a duplicate of issue 10451 ***