www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18845] New: Extern(C++) class with no virtual functions


          Issue ID: 18845
           Summary: Extern(C++) class with no virtual functions
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: turkeyman gmail.com

I just encountered a gotcha where D doesn't support extern(C++) classes with no

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

May 09 2018