May 25, 2021

On Tuesday, 25 May 2021 at 17:52:14 UTC, Gavin Ray wrote:

>

void takesADerived(Derived derived);

extern class Derived : Base1, Base2

Like I said in chat, these are NOT the same thing. The C++ Derived is a sibling class, not a parent, child, nor binding to the D Derived.

All your attempts to pass one off as the other is problematic. If you want to bind to the C++ derived, don't provide any bodies for the functions - just bind. If you want to inherit from it, you must first declare the binding in D, then inherit.

May 25, 2021

On Tuesday, 25 May 2021 at 18:12:27 UTC, Gavin Ray wrote:

>

On Tuesday, 25 May 2021 at 18:03:00 UTC, evilrat wrote:

>

That last one with someInt is what I warned about. D ctor messed up class layout, in this simple case where class data isn't used it almost works, but will be practically unusable in real scenarios.

Ah =/
You have this in your code example:

static assert(Derived.someInt.offsetof == 16); // that's important otherwise D ctor will mess up everything

Would this fix it, or is it just not super viable to hack around C++ multiple inheritance in D?

Maybe generating some wrapper C++ code to be linked could help too?
I'm not sure though/don't really know enough to say

Both this features uses mixins, but does conceptually different things, my example with manual vtable casts is simpler but more mechanical, and it basically mimics how it actually works.

Anyway the problem is with D side, compiler emits incorrect type info/layouts (no wonder, it is clearly stated multiple inheritance not supported), and then everything explodes.

So one of the possible workarounds is to separate class layout and API with mixins/templates. No idea how it will affect usability though, it's quite possible that extending such horrible construct from D side would be cumbersome, too much PITA to do real job using that thing.
Hard to say for sure without experiments.

Also like I said, D already does half of the work, it just needs to collect all base classes and arrange vtable. One of the potential blockers could be frontend architecture, I don't know how much stuff such change would break, I think pretty much everything was designed with single base class in mind.
Like this one, it has 'this' pointer, ctor/dtor and fields, but no mention about layouts anywhere.
https://github.com/dlang/dmd/blob/master/src/dmd/aggregate.d#L86
The closest what it could be is
https://github.com/dlang/dmd/blob/master/src/dmd/aggregate.d#L279

1 2 3
Next ›   Last »