[dmd-internals] DMC vs DMD C++ mangling

Rainer Schuetze r.sagitario at gmx.de
Fri Apr 19 09:23:34 PDT 2013


On 18.04.2013 15:22, Daniel Murphy wrote:
> Hi all,
>
> I have come across one strange case where dmd and dmc produce different
> mangling for seemingly identical declarations.
>
> D:
> extern(C++) const(const(bool)*) gc_pi1; // mangled as ?gc_pi1@@3PB_NB
>
> C++:
> extern bool const * const gc_pi1; // mangled as ?gc_pi1@@3QB_NB
>
> So we have '[PQ]B_NB' which translates to '[pointer/const pointer] const
> bool const' where both of the const modifiers (for some reason) apply to
> the bool, not the pointer.

If I understand Agner Fog 
(http://www.agner.org/optimize/calling_conventions.pdf) correctly, 
"QB_NB" is parsed as QBtype with "QB" translating to "type *const" and 
type "_NB" translating to "const bool". So the const modifiers bind to 
different entities.


>
> Is dmd incorrectly printing 'P' instead of 'Q' or have I missed something?

I suspect dmd might be omitting the transitive "const" to allow leaving 
"const char *" as is instead of requiring "const(char)*" when 
translating C++ headers to D.

>
> Thanks,
> Daniel.
>
> PS If anybody with msvc installed could try this I would be very grateful.

cl 15.0 and 16.0 (from VS2008 and VS2010) mangle it the same as dmc:

error LNK2019: unresolved external symbol "bool const * const gc_pi1" 
(?gc_pi1@@3QB_NB) referenced in function _main




More information about the dmd-internals mailing list