const(Class) is mangled as Class const* const
turkeyman at gmail.com
Wed Aug 26 01:58:21 UTC 2020
On Tue, Mar 28, 2017 at 11:21 PM kinke via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:
> On Tuesday, 28 March 2017 at 12:55:02 UTC, deadalnix wrote:
> > On Tuesday, 28 March 2017 at 08:30:43 UTC, kinke wrote:
> >> What I don't get is why it's considered important to have a
> >> matching C++ mangling for templates across D and C++ - what
> >> for? I only care about mangling wrt.
> > If you still think this is a mangling problem, please reread my
> > first response in this thread.
> You don't seem to get my point, I don't know why it's apparently
> that hard. I don't want to be able to express both `const T*
> const` AND `const T*` in C++, I only want D's const(Object)
> mangling to express solely the former instead of the latter, as
> there's no use for the double-const, except maybe for templates
> as Walter pointed out, but there's no template interop between D
> and C++ anyway.
> I absolutely don't care that it's inconsistent to what a D
> const(Object) reference actually is (both pointer and class
> const) when passing such a thing BY VALUE to C++. As I said,
> there's no C++ analogon for D object references, so why not have
> it be a special case in the C++ mangler...
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
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.
There's some precedent for this too; C++ actually strips the head const off
of the types when mangling function arguments.
void t(const int *);
void t(const int * const);
Both functions mangle to `void t(const int *)` (and this is an invalid
overload). The pointer const is not present in the mangling here.
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++).
The case where it can go either way is with templates:
void foo<const Class * const>();
void foo<const Class *>();
These are valid overloads... and D can only express the former
instantiation, which basically never occurs in C++.
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
I think even in the template case, we should mangle const(Class) to `const
Class *`, and not `const Class * const`.
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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Digitalmars-d