extern(C++, ns)

Manu via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 18 06:46:34 PST 2016


On 18 January 2016 at 20:24, Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 1/18/2016 12:47 AM, Manu via Digitalmars-d wrote:
>>
>> Next problem:
>
>
> I don't think anyone has tested C++ multiple inheritance against D
> interfaces. I'm not even sure if you're running C++ on Linux or Windows -
> and the C++ layout can certainly differ between those compilers.

This particular build is DMD-Win64 tested against against
MSC2015-Win64 (I think this is the natural counterpart).
I suspect some possibly compiler-agnostic funny business going on here
though, since the codegen is dereferencing a vtable at the same
location that it seems to think 'y' is living at.
I didn't expect this to work. I have no idea how D interfaces are
implemented, but I doubted they're the same as C++ multiple
inheritance(?).
This fairly typical C++ code matches the D multiple inheritance
semantics though (ie, single inheritance+interfaces), which is fairly
common in C++, COM etc.
It would be nice to support this pattern. I don't see any reasons why
D should struggle to express it, it's just another case of struct
layout difference(?).

I am now blocked on this. So hopefully it can be done.
I think this is the last hurdle inhibiting CI and
cross-platform/compiler testing, or usage of D in our project in
general.

> In any case, you can check the layout by running obj2asm on the resulting .o
> file and looking at the data for the struct initializer.

I'll try this tomorrow.

> A known problem is that D doesn't put destructors in the vtbl[] for C++
> classes, although it should. Also, virtual destructors on Linux 64 consume 2
> slots in the vtbl[], which surprised me.

Okay, well we have builds for all common platforms, so maybe we'll hit
this when we have working code submit for CI testing.
I'm sure I can stress cross-platform compliance on this one when it works.

> Anyhow, things are getting a bit advanced here, and also it has nothing to
> do with namespaces :-) I'll have to do some more investigating.

Yeah, this is now in new territory, since name lookup seems to be working.
Shall I spawn a new thread?


More information about the Digitalmars-d mailing list