[Issue 15812] New: static struct inside extern(C++) class cannot be used as key to associative array

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


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

          Issue ID: 15812
           Summary: static struct inside extern(C++) class cannot be used
                    as key to associative array
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

Given:

extern (C++) class C {
    struct S {
        int ti;

        this(int ti) {
            this.ti = ti;
        }

        size_t toHash() const @safe nothrow {
            return ti;
        }

        bool opEquals(ref const S s) @trusted const {
            return s.ti == ti;
        }
    }
}

alias SS = C.S;

void main() {
    int[SS] aa;
    auto s = SS(3);
    aa[s] = 4;
}

fails with:

foo10.d(22): Error: AA key type S should have 'size_t toHash() const nothrow
@safe' if opEquals defined

but it works if the extern (C++) is removed.

--


More information about the Digitalmars-d-bugs mailing list