const(Class) is mangled as Class const* const

kinke via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 27 02:10:31 PDT 2017


On Sunday, 26 March 2017 at 17:41:57 UTC, Benjamin Thaut wrote:
> 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.

I agree that C++-mangling a const D object reference as `const T 
*const` isn't helpful although it would be consistent with D 
semantics. As deadalnix pointed out, the const for the pointer 
itself only concerns the callee and not the caller. I sometimes 
use `void foo(const T *bla); ... void foo(const T *const bla) { 
... }` if I find it useful to make clear that `bla` won't change 
in my foo() implementation, but I never use the second const in 
the function declaration in the header as it's just useless 
clutter for the caller.

Having said that, you can only declare a C++ type as D class if 
it's exclusively passed and returned as pointer (at least in the 
parts you are going to interface with via D). This was true for 
the C++-based DMD front-end and would also be true for some types 
used in LLVM. But as soon as you want to interface with a C++ 
function taking an object as `[const] T&`, afaik you're f*cked 
and need to declare it as D struct. So I'm quite skeptical that 
I'll often be able to use D classes to represent C++ types.


More information about the Digitalmars-d mailing list