Bug 21392 – extern(C++) No support for virtual inheritance ABI

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-11-14T18:20:01Z
Last change time
2024-12-13T19:12:45Z
Assigned to
No Owner
Creator
Iain Buclaw
Moved to GitHub: dmd#17998 →

Comments

Comment #0 by ibuclaw — 2020-11-14T18:20:01Z
Example program --- #include <stdio.h> struct A { virtual void f2 () {}; virtual void f3 () {}; }; struct B : virtual public A { virtual void f3 () {}; }; struct C : public A, public B { virtual void f4 () {}; }; struct D : virtual public B, virtual public C, virtual public A { virtual void f2 () { }; virtual void f3 () { printf("this = %p\n", this); } virtual void f4 () { }; virtual void f5 () { }; virtual void f6 () { }; }; D *makeD() { return new D; } --- extern(C++, struct) { interface A { void f2(); void f3(); } interface B : A { void f3(); } interface C : A, B { void f4(); } interface D : B, C, A { void f2(); void f3(); void f4(); void f5(); void f6(); } D makeD(); } int main() { C c = makeD(); (cast(B)c).f3(); // !!! SEGV !!! return 0; } ---
Comment #1 by iamthewilsonator — 2021-03-25T09:42:54Z
is this the same issue as https://issues.dlang.org/show_bug.cgi?id=19192 ? it has just been fixed.
Comment #2 by ibuclaw — 2021-03-25T16:30:56Z
(In reply to Nicholas Wilson from comment #1) > is this the same issue as https://issues.dlang.org/show_bug.cgi?id=19192 ? > it has just been fixed. Unless that issue adds virtual inheritance to D, I'd say no. This issue is more about ABI compatibility with thunks. In C++ you have have thunks adjust the `this' pointer for straightforward inheritance (same as D). However for virtual inheritance, thunks instead adjust the `__vptr', or both the `this' and `__vptr' pointers within the same thunk. D has no notion of fixing the index into the vtable during a thunk call.
Comment #3 by robert.schadek — 2024-12-13T19:12:45Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17998 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB