The following code:
extern (C++) void foo(const(char)[]) {}
Gives the following error:
Error: Internal Compiler Error: type const(char)[] can not be mapped to C++
@jacob-carlborg updated dlang/dmd pull request #8120 "Fix issue 18716: type `const(char)[]` can not be mapped to C++" fixing this issue:
- Fix issue 18716: type `const(char)[]` can not be mapped to C++
D arrays don't have any corresponding type in C++. Instead we mangle
it as a templated struct with the name `__dslice`, i.e.
`struct __dslice(T)`, where `T` is the element type of the array. For
an array of ints it would be mangled as the following type:
`__dslice!int`.
https://github.com/dlang/dmd/pull/8120
Comment #3 by nick — 2023-06-24T15:26:30Z
Note that:
extern (C) void foo(const(char)[]) {}
and `dmd -HC` generates:
template<typename T>
struct _d_dynamicArray final
{
size_t length;
T *ptr;
...
};
...
extern "C" void foo(_d_dynamicArray< const char > __param_0_);
So hopefully this could happen for extern(C++) too.
Comment #4 by robert.schadek — 2024-12-13T18:58:10Z