You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just encountered a gotcha where D doesn't support extern(C++) classes with no vtable.
In C++, if a class has no virtual functions, there is no vtable.
If a virtual is added to a derived class, the vtable is pre-pended to the base.
Is it possible to replicate this in extern(C++)?
We have had a bunch of gotchas related to this.
You can argue that a base class with no virtual functions is a struct, and that may be true, except that its *intent* is that it shall be derived from. D can not derive a class from a struct, so the base-with-no-virtuals needs to be expressed as a class in D for the arrangement to translate and interact with D code.
The text was updated successfully, but these errors were encountered:
See: The giant workaround I had to do for Binderoo for this very thing in my DConf 2017 talk.
I believe the reason classes always have a vtable is so safe casting is still guaranteed. But that's just an assumption.
What does "safe casting" mean?
You mean that it might require pointer adjustment?
I mean, it's absolutely necessary that when casting extern(C++) classes, that some special logic is applied which may need to perform a pointer adjustment, just like when casting C++ classes in C++ ;)
We can't escape that. We either need to support it, or it's just broken.
At very least, we should emit an error when an extern(C++) class is declared with no virtual members saying it's not supported.
Manu reported this on 2018-05-09T21:10:50Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=18845
CC List
Description
The text was updated successfully, but these errors were encountered: