The following crashes when compiled and run:
extern (C++) class C {
int ti;
this(int ti) {
this.ti = ti;
}
size_t toHash() const @safe nothrow {
return ti;
}
bool opEquals(Object s) {
return (cast(C)s).ti == ti;
}
}
void main() {
int[C] aa;
auto s = new C(3);
aa[s] = 4;
assert(aa[s] == 4);
}
Comment #1 by pro.mathias.lang — 2020-02-19T05:21:25Z
*** Issue 13875 has been marked as a duplicate of this issue. ***
Comment #2 by pro.mathias.lang — 2020-02-19T05:23:03Z
*** Issue 15765 has been marked as a duplicate of this issue. ***
Comment #3 by pro.mathias.lang — 2020-02-19T05:23:36Z
Martin posted the following comment about why this happens:
```
Because TypeInfo_Class casts every void* to a standard Object, it ends up calling the wrong vtable entries for operations like getHash.
I think we need a dedicated TypeInfo_CppClass that is similar to TypeInfo_Struct with it's xopEquals and xopHash in order to fix this bug.
C++ classes don't inherit from the common Object class, so those methods must not exist.
```
Comment #4 by robert.schadek — 2024-12-13T18:47:10Z