This doesn't work, but it should: alias X = NS.X; extern (C++, NS) struct X {} This works fine: extern (C++, NS) struct X {} alias X = NS.X;
This may be related to apparent circular referencing issues: module x; import y; extern(C++, ns) class X { Y v; } module y; import x; extern(C++, ns) class Y { X v; } y.d(3): Error: undefined identifier 'X' extern(C++, ns) class Y { x.X v; } y.d(3): Error: undefined identifier 'X' in module 'x' extern(C++, ns) class Y { x.ns.X v; } y.d(3): Error: identifier 'X' of 'x.ns.X' is not defined y.d(3): Error: x.ns.X is used as a type import x : XX = X; extern(C++, ns) class Y { XX v; } y.d(2): Error: module x import 'X' not found import x : NS = ns; extern(C++, ns) class Y { NS.X v; } y.d(3): Error: identifier 'X' of 'NS.X' is not defined y.d(3): Error: NS.X is used as a type import x : XX = ns.X; extern(C++, ns) class Y { XX v; } y.d(2): Error: ';' expected y.d(2): Error: no identifier for declarator X I dunno!
(In reply to Manu from comment #1) > This may be related to apparent circular referencing issues: > > module x; > import y; > extern(C++, ns) class X { Y v; } > > > module y; > import x; > extern(C++, ns) class Y { X v; } > > y.d(3): Error: undefined identifier 'X' A misunderstanding of how namespace lookup works in D. Namespaces in D: 1. follow D lookup rules 2. follow C++ mangling rules The example of: Y y; is clearly assuming that C++ namespace lookup rules are being followed. They are not, D lookup rules are. Y is declared in x.y.ns, not x.x.ns. As far as the compiler is concerned, x.y.ns and x.x.ns are different namespaces (although they will mangle the same). Thus, "Y" should be "x.y.ns.Y". You can see this if you replace "extern(C++, ns)" with "struct ns". You'll get the SAME error message! Not a D bug. > extern(C++, ns) class Y { x.X v; } > > y.d(3): Error: undefined identifier 'X' in module 'x' Same issue. Should be "x.ns.X", as X is in the scope of x.ns. Not a D bug. > extern(C++, ns) class Y { x.ns.X v; } > > y.d(3): Error: identifier 'X' of 'x.ns.X' is not defined > y.d(3): Error: x.ns.X is used as a type Filed as https://issues.dlang.org/show_bug.cgi?id=15503 > import x : XX = X; > extern(C++, ns) class Y { XX v; } > > y.d(2): Error: module x import 'X' not found Because it's ns.X, not X. Not a D bug. > import x : NS = ns; > extern(C++, ns) class Y { NS.X v; } > > y.d(3): Error: identifier 'X' of 'NS.X' is not defined > y.d(3): Error: NS.X is used as a type Probably the same issue as https://issues.dlang.org/show_bug.cgi?id=15503 > import x : XX = ns.X; > extern(C++, ns) class Y { XX v; } > > y.d(2): Error: ';' expected > y.d(2): Error: no identifier for declarator X Supporting the . in the import would be an enhancement request.
https://github.com/D-Programming-Language/dmd/pull/5330
Thanks Walter! Does this also address the case in the initial bug report?
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/11d309ff1c766715e06671bbb586809a9b0d5af8 fix Issue 15389 - extern(C++) forward referencing problem https://github.com/D-Programming-Language/dmd/commit/b21432a31061b7106c3d2d9f0d4b42a2faa070e0 Merge pull request #5330 from WalterBright/fix15389 fix Issue 15389 - extern(C++) forward referencing problem
Commit pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/8399e29190a31746f695ae517cc28ec29806ae8a Merge pull request #5330 from WalterBright/fix15389 fix Issue 15389 - extern(C++) forward referencing problem
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/8399e29190a31746f695ae517cc28ec29806ae8a Merge pull request #5330 from WalterBright/fix15389
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/11d309ff1c766715e06671bbb586809a9b0d5af8 fix Issue 15389 - extern(C++) forward referencing problem https://github.com/D-Programming-Language/dmd/commit/b21432a31061b7106c3d2d9f0d4b42a2faa070e0 Merge pull request #5330 from WalterBright/fix15389
Commit pushed to dmd-cxx at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/0fbec9bdf7d959db71e7b0a9b12d89e44493f340 Issue 15389 - extern(C++) forward referencing problem