[Issue 15813] New: extern (C++) classes cannot be used as associative array keys

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Mar 19 02:29:08 PDT 2016


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

          Issue ID: 15813
           Summary: extern (C++) classes cannot be used as associative
                    array keys
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

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);
}

--


More information about the Digitalmars-d-bugs mailing list