Bug 15647 – Casting from one C++ interface in a hierarchy to another is a noop

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-02-05T10:21:00Z
Last change time
2016-02-06T21:32:32Z
Keywords
C++
Assigned to
nobody
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2016-02-05T10:21:52Z
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'); }
Comment #1 by bugzilla — 2016-02-05T10:32:53Z
Comment #2 by github-bugzilla — 2016-02-06T21:32:31Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/91a859cdad8cbbe5b6c20a0f8eb4e1da07e1f70a fix Issue 15647 - Casting from one C++ interface in a hierarchy to another is a noop https://github.com/D-Programming-Language/dmd/commit/3a1a7e2196497d2dbd233a4bb4c2b2c7a7d3ebb2 Merge pull request #5402 from WalterBright/fix15647 fix Issue 15647 - Casting from one C++ interface in a hierarchy to an…