www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15626] New: extern(C++) calling crash

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

          Issue ID: 15626
           Summary: extern(C++) calling crash
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: turkeyman gmail.com

Created attachment 1581
  --> https://issues.dlang.org/attachment.cgi?id=1581&action=edit
test case

D:
------------------

module lib;

extern(C++) class C
{

}

extern(C++) interface I
{
    void f();
}

extern(C++) abstract class BaseImpl(C, I) : I
{
    C instance;
}

// Bonus points: this is extern(C) because the C++ mangler doesn't work on this
type.
extern(C) void test(BaseImpl!(C, I) impl)
{
    impl.f();
}



C++:
------------------


#include <stdio.h>

class C
{

};

class I
{
  virtual void f() = 0;
};

template <typename C, typename I>
class BaseImpl : public I
{
  C *pInstance = (C*)(size_t)0xBAADF00D;
};

class Impl : public BaseImpl<C, I>
{
  void f() override final
  {
    printf("!!");
  }
};

extern "C" {
  extern void test(BaseImpl<C, I> *pImpl);
}

void main()
{
  Impl *i = new Impl;
  test(i);
}

--
Jan 29