On Sunday, 3 January 2016 at 16:18:13 UTC, Walter Bright wrote:
No. If D is to support C++ namespaces, it has to support declaring the same identifier for different purposes in different namespaces. C++ namespaces have different scopes in C++. Doing anything else would make it impossible to connect to perfectly legitimate C++ programs. The WHOLE POINT of C++ namespaces is to support declaring the same identifier in different namespaces.

Yes, but the point of `extern(C++, ns)` is NOT to achieve the same in D! D has its own mechanisms for that, primarily the module system, as well as hacks like static structs. And I don't see how Manu's suggestion would make it impossible to link to some C++ programs. Can you give an example?



This would solve a lot of awkward issues.

It'd be a river of bug reports, because sure as shootin', people are going to try to interface to this C++ code:

  namespace ns1 { int identifier; }
  namespace ns2 { int identifier; }

And why shouldn't they? It's correct and legitimate C++ code.

I guess in reality this would not be a frequent thing. Most real C++ code will have both instances of `identifier` declared in different header files, and D's modules will usually closely mirror those, so they will end up in different modules on the D side.

In the rare case the same identifier actually does appear twice in the same module, static structs can be used:

struct ns1 {
    extern(C++, ns1):
    int identifier;
}
struct ns2 {
    extern(C++, ns2):
    int identifier;
}

Reply via email to