www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15647] New: Casting from one C++ interface in a hierarchy to

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

          Issue ID: 15647
           Summary: Casting from one C++ interface in a hierarchy to
                    another is a noop
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

When it shouldn't be, i.e. this crashes:

extern(C) int printf(const char*, ...);

/*******************************************************/

extern (C++)
{
    interface IA25
    {
        char a();
    }

    interface IB25
    {
        char b();
    }

    interface IC25 : IA25, IB25
    {
        char c();
    }

    interface ID25
    {
        char d();
    }

    interface IE25 : IC25, ID25
    {
        char e();
    }

    class Foo25 : IE25
    {
        int x = 9;
        char a() { printf("a.this = %p\n", this); return('a'); }
        char b() { printf("b.this = %p\n", this); return('b'); }
        char c() { printf("c.this = %p\n", this); return('c'); }
        char d() { printf("d.this = %p\n", this); return('d'); }
        char e() { printf("e.this = %p\n", this); return('e'); }
    }
}

void main()
{
    auto foo = new Foo25;
    printf("Foo: %p %c %c %c %c %c\n", foo, foo.a, foo.b, foo.c, foo.d, foo.e);
    IA25 a = foo;
    printf("A: %c\n", a.a);
    assert(a.a == 'a');
    IB25 b = foo;
    printf("B: %c\n", b.b);
    assert(b.b == 'b');
    IC25 c = foo;
    printf("C: %p %c %c %c\n", c, c.a, c.b, c.c);
    assert(c.a == 'a');
    assert(c.b == 'b');
    assert(c.c == 'c');
    ID25 d = foo;
    printf("D: %c\n", d.d);
    assert(d.d == 'd');
    IE25 e = foo;
    printf("E: %c %c %c %c %c\n", e.a, e.b, e.c, e.d, e.e);
    assert(e.a == 'a');
    assert(e.b == 'b');
    assert(e.c == 'c');
    assert(e.d == 'd');
    assert(e.e == 'e');

    b = e;
    printf("IB25: %c\n", b.b);
    assert(b.b == 'b');
}

--
Feb 05 2016