Bug 15389 – extern(C++) forward referencing problem

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-29T10:13:00Z
Last change time
2017-08-02T08:07:38Z
Keywords
C++, industry
Assigned to
nobody
Creator
turkeyman
See also
https://issues.dlang.org/show_bug.cgi?id=15503, https://issues.dlang.org/show_bug.cgi?id=15519

Comments

Comment #0 by turkeyman — 2015-11-29T10:13:55Z
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;
Comment #1 by turkeyman — 2016-01-03T07:10:49Z
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!
Comment #2 by bugzilla — 2016-01-03T08:14:53Z
(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.
Comment #3 by bugzilla — 2016-01-04T10:53:06Z
Comment #4 by turkeyman — 2016-01-04T11:04:37Z
Thanks Walter! Does this also address the case in the initial bug report?
Comment #5 by github-bugzilla — 2016-01-06T10:57:18Z
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
Comment #6 by github-bugzilla — 2016-01-06T17:40:37Z
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
Comment #7 by github-bugzilla — 2016-01-24T22:47:50Z
Comment #8 by github-bugzilla — 2016-03-19T20:21:30Z
Comment #9 by github-bugzilla — 2017-08-02T08:07:38Z
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