cpp_interface.html:
> a D interface with the attribute of extern (C++) will have a virtual function
> pointer table (vtbl[]) that exactly matches C++'s [...] in C++ the first
> entry points to the first virtual function.
extern (C++) interface A { void foo(); void bar(); }
A a = ...;
So calling a.foo() should call vtbl[0], instead D calls vtbl[1] as if it where a normal D interface.
Comment #1 by niqbmozgvx — 2007-11-23T11:08:02Z
*** Bug 1688 has been marked as a duplicate of this bug. ***
Comment #2 by niqbmozgvx — 2007-11-24T03:08:53Z
BTW this functionality of an interface, in which the slot 0 of the vtable[] is NOT used by a ClassInfo pointer, is needed for a lot of interfaces in the windows header files which are NOT derived from IUnknown. Mainly the whole DirectX 10 part.
Comment #3 by wazar.leollone — 2013-05-19T08:20:35Z
(In reply to comment #2)
> BTW this functionality of an interface, in which the slot 0 of the vtable[] is
> NOT used by a ClassInfo pointer, is needed for a lot of interfaces in the
> windows header files which are NOT derived from IUnknown. Mainly the whole
> DirectX 10 part.
PING. Do this issue is invalid?
Comment #4 by andrei — 2013-11-15T21:03:49Z
This segfaults:
extern (C++) interface A { void foo(); void bar(); }
extern (C++) class B : A { void foo() { } void bar() { } }
void main()
{
A a = new B;
a.foo();
}
It actually segfaults even without the interface and the call.
Comment #5 by yebblies — 2013-11-15T21:42:33Z
I'm pretty sure this bug was fixed by https://github.com/D-Programming-Language/dmd/pull/2441https://github.com/D-Programming-Language/dmd/pull/2441/files#diff-51c17721512749ee0a457d576c82eb2eR638
This code
=====================
extern (C++) interface A { void foo(); void bar(); }
void main()
{
A a;
a.foo();
}
====================
Generates:
__Dmain PROC NEAR
; COMDEF __Dmain
xor eax, eax ; 0000 _ 31. C0 // a = null
mov ecx, eax ; 0002 _ 89. C1
mov edx, dword ptr [eax] ; 0004 _ 8B. 10 // edx = a.__vptr[0]
call dword ptr [edx] ; 0006 _ FF. 12 // edx()
xor eax, eax ; 0008 _ 31. C0
ret ; 000A _ C3
__Dmain ENDP
ie foo is called from vtbl index 0
(In reply to comment #4)
> This segfaults:
>
> extern (C++) interface A { void foo(); void bar(); }
>
> extern (C++) class B : A { void foo() { } void bar() { } }
>
> void main()
> {
> A a = new B;
> a.foo();
> }
>
> It actually segfaults even without the interface and the call.
It does? What platform? Are you using git head or a release?
Comment #6 by andrei — 2013-11-15T22:12:18Z
Ah. I was using DMD64 D Compiler v2.064-devel-acc0cb0. OK to close then?
Comment #7 by yebblies — 2013-11-15T22:59:25Z
(In reply to comment #6)
> Ah. I was using DMD64 D Compiler v2.064-devel-acc0cb0. OK to close then?
Can you try head on your machine? That commit is fairly recent - there have been no changes I'm aware of to this code since then.
The vtable access looks correct for win64 codegen.
It's quite possible there's a non-windows problem with extern(C++) classes lurking somewhere in there...
Comment #8 by andrei — 2013-11-16T02:01:47Z
Worked as expected after I pulled the latest. Closing.