const(Class) is mangled as Class const* const

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Sun Mar 26 15:29:56 PDT 2017


On Sunday, 26 March 2017 at 17:41:57 UTC, Benjamin Thaut wrote:
> On Sunday, 26 March 2017 at 14:30:00 UTC, deadalnix wrote:
>>
>> It's consistent. D's const is transitive, and D doesn't allow 
>> you to specify const on the indirection of a reference type. 
>> So there is no problem on the C++ mangling side of things, 
>> but, arguably, there is one in D's sementic, that isn't new.
>
> I disagree. When binding C++ code to D I don't care about D's 
> const rules. I care about the C++ const rules. There are 
> thousands of C++ libraries out there that can't be bound to D 
> because they use const Class* instead of const Class* const. So 
> in my eyes there is definitly something wrong with the C++ 
> mangling of D.

It is clear that you won't be able to express 100% of C++ in D, 
that would require to important all the weird parts of C++ into 
D, but if we are doing so, why use D in the first place ?

Note that using const Class* in C++ is essentially useless. The 
class remains mutable and the reference is local the the callee 
anyway, so it doesn't change anything for the caller. Such a 
pattern is most likely indicative of a bug on the C++ side, or at 
least of code that do not do what the author intend to.


More information about the Digitalmars-d mailing list