www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15813] New: extern (C++) classes cannot be used as

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 puremagic.com
          Reporter: bugzilla 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);
}

--
Mar 19 2016