Bug 15813 – extern (C++) classes cannot be used as associative array keys

Status
NEW
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-19T09:29:08Z
Last change time
2024-12-13T18:47:10Z
Keywords
C++
Assigned to
No Owner
Creator
Walter Bright
See also
https://issues.dlang.org/show_bug.cgi?id=13875
Moved to GitHub: dmd#19106 →

Comments

Comment #0 by bugzilla — 2016-03-19T09:29:08Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19106 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB