<div dir="ltr"><div dir="ltr">On Tue, Mar 28, 2017 at 11:21 PM kinke via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tuesday, 28 March 2017 at 12:55:02 UTC, deadalnix wrote:<br>
> On Tuesday, 28 March 2017 at 08:30:43 UTC, kinke wrote:<br>
>> What I don't get is why it's considered important to have a <br>
>> matching C++ mangling for templates across D and C++ - what <br>
>> for? I only care about mangling wrt.<br>
><br>
> If you still think this is a mangling problem, please reread my <br>
> first response in this thread.<br>
<br>
You don't seem to get my point, I don't know why it's apparently <br>
that hard. I don't want to be able to express both `const T* <br>
const` AND `const T*` in C++, I only want D's const(Object) <br>
mangling to express solely the former instead of the latter, as <br>
there's no use for the double-const, except maybe for templates <br>
as Walter pointed out, but there's no template interop between D <br>
and C++ anyway.<br>
<br>
I absolutely don't care that it's inconsistent to what a D <br>
const(Object) reference actually is (both pointer and class <br>
const) when passing such a thing BY VALUE to C++. As I said, <br>
there's no C++ analogon for D object references, so why not have <br>
it be a special case in the C++ mangler...<br></blockquote><div><br></div><div>I've lost sleep on this point for many years. I keep changing my mind between purity and what's actually useful, but I've settled on what you say here.<br></div><div>It is my opinion from a decade of experience that D should mangle const(Class) as `const Class *`. It is what you want 99% of the time.</div><div><br></div><div><br></div><div>There's some precedent for this too; C++ actually strips the head const off of the types when mangling function arguments.</div><div>For instance:<br></div><div>  void t(const int *);</div><div>  void t(const int * const);</div><div>Both functions mangle to `void t(const int *)` (and this is an invalid overload). The pointer const is not present in the mangling here.</div><div>We follow this rule when mangling const class arguments to functions. In this case, we strip the pointer const from the mangling (as does C++).</div><div><br></div><div>The case where it can go either way is with templates:</div><div>  void foo<const Class * const>();</div><div><div>  void foo<const Class *>();</div><div>These are valid overloads... and D can only express the former instantiation, which basically never occurs in C++.</div><div><br></div><div>I accept that they are functionally different things, and 'correct-ness' says that we should indeed mangle the former one, but that's just not useful.</div><div>I think even in the template case, we should mangle const(Class) to `const Class *`, and not `const Class * const`.<br></div></div><div>It is possible to conjure an exploit where C++ may modify a const D variable across the binding, but that's extremely contrived, and the capabilities our current mangling limits us from is an endless pain in the arse.</div></div></div>