<div dir="ltr">C++ namespacing is causing me endless, and I mean *endless* trouble.<div>This idea that we express the C++ namespace hierarchy in D is the main problem.</div><div>I don't think C++ namespaces should interfere with D scoping rules, they should be purely for mangling.</div><div>It creates a whole bundle of edge cases which either don't have work arounds, or REALLY awkward workarounds which typically have a heavy impact on all the regular D code that the C++ code interacts with.</div><div><br></div><div>Not least of which is that C++ namespaces usually span the entire project, and in D a C++ namespace can only appear in one module ever.</div><div>Declaring symbols with the same C++ namespace in different modules leads to multiple definition errors, and if you are super-careful to avoid those, you gain name resolution issues in it's place.</div><div><br></div><div>It is also very awkward that a C++ namespace can't be the same as a top level package name. My top level package is named the same as one of my C++ namespaces... what do I do? It gets ugly real fast.<br></div><div><br></div><div>The main problem extends from this situation:</div><div><br></div><div>module x.y;</div><div><br></div><div>extern(C++, ns) struct Y {}<br></div><div><div><br></div><div><br></div></div><div>module ns.m;<br></div><div><br></div><div>import x.y; // fail, the c++ namespace is already present (top level module)</div><div>import x.y : ns.Y; // fail, '.' can't appear here</div><div><div>import x.y : Y; // fail, not found</div></div><div><br></div><div>// This **sometimes** works, and it's very brittle</div><div>static import x.y;</div><div>alias Y = x.y.Y;</div><div><br></div><div><br></div><div>Thing is, I'm not declaring a C++ object, I'm declaring a D object, the only thing being that struct's take care to maintain common binary layout, and functions just mangle like C++ so that my code links. I'm in D, I'm declaring my stuff in the D module where it should be scoped, and where other D code should expect to find it. I don't see any point in building the C++ hierarchy in this space. C++ namespace rules are incompatible with D; you can litter them through C++ code, and add new symbols to C++ namespaces from anywhere... this is fundamentally incompatible with D, and no further reasoning should be required to conclude that it can't be reproduced, so it should be for mangling purposes only.</div><div><br></div><div>I have spent **days**, actually, weeks of my free time trying to make my tiny bit of code build, and it's just nothing but trouble after trouble. I have completely restructured my code at least 3 times to try and find a way to make it fit together in a way that's both practical and works, but I just can't. It always hits some brick wall somewhere.</div><div><br></div><div>extern(C++, NS) looks okay in isolated tests/experiments, but try and actually use it, and you will become very frustrated.</div><div><br></div><div>Please, fix this. I'm almost done. I'm really struggling to keep this dream alive.</div></div>