www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16060] New: extern(C++) abstract base class and interface

https://issues.dlang.org/show_bug.cgi?id=16060

          Issue ID: 16060
           Summary: extern(C++) abstract base class and interface
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: turkeyman gmail.com

In this case, we have an example of single-inheritance in C++, but D treats
this construct as multiple-inheritance, and the struct's don't match.


C++:
----

#include <new>

class I
{
public:
  virtual void f1() = 0;
  virtual float f2() = 0;
};

class Test : public I
{
public:
  int t;

  Test(int t) : t(t) {}
};

class Blah : public Test
{
public:
  Blah() : Test(0xbaadf00d) {}

  void f1() {}
  float f2() { return 10.f; }
};

extern "C" {
  I* test()
  {
    return new Blah;
  }

  Test* test2()
  {
    return new Blah;
  }
}



D:
--

import std.stdio;

extern (C++) interface I
{
  void f1();
  float f2();
}

extern (C++) abstract class Test : I
{
  int t;
}

extern (C) I test();
extern (C) Test test2();

int main(string[] argv)
{
  auto i = test();
  i.f1();

  auto j = test2();
  float f = j.f2(); // CRASH! looks up vtable address: [i + 8], expect: vtable
at [i]

  writeln("Hello D-World! ", f);
  return 0;
}

--
May 22 2016