[Issue 15389] extern(C++) forward referencing problem
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Jan 3 00:14:53 PST 2016
https://issues.dlang.org/show_bug.cgi?id=15389
Walter Bright <bugzilla at digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bugzilla at digitalmars.com
--- Comment #2 from Walter Bright <bugzilla at digitalmars.com> ---
(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.
--
More information about the Digitalmars-d-bugs
mailing list