I was trying to interface FreeBasic with a class written in C++ and compiled with GCC
Normal methods worked as expected, but virtual methods seemed to be "shifted by one". Basically, calling one virtual method from FreeBasic activates the previous virtual method in the C++ class
Looks like this happens because C++ implements two destructors, not just one:
https://eli.thegreenplace.net/2015/c-deleting-destructors-and-virtual-operator-delete/
https://stackoverflow.com/questions/17960917/why-there-are-two-virtual-destructor-in-the-virtual-table-and-where-is-address-o
https://stackoverflow.com/questions/44558119/why-do-i-have-two-destructor-implementations-in-my-assembly-output
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#obj-ctor
The entries for virtual destructors are actually pairs of entries. The first destructor, called the complete object destructor, performs the destruction without calling delete() on the object. The second destructor, called the deleting destructor, calls delete() after destroying the object. Both destroy any virtual bases; a separate, non-virtual function, called the base object destructor, performs destruction of the object but not its virtual base subobjects, and does not call delete().
More details are discussed here: https://freebasic.net/forum/viewtopic.php?p=272429#p272429
Pull request for deleting destructor at: Add deleting destructor for c++ ABI #303
This addition was merged in as part of Thiscall calling convention -gen gcc only #304
More testing is required with the
thiscallcalling convention, however, the virtual table should be correct for types declared witinextern "c++"blocks.