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.
Introduced in https://github.com/dlang/dmd/pull/3054
It will work if toHash() is declared as extern (D).
@WalterBright created dlang/dmd pull request #10782 "fix Issue 15812 - static struct inside extern(C++) class cannot be us…" fixing this issue: - fix Issue 15812 - static struct inside extern(C++) class cannot be used as key to associative array https://github.com/dlang/dmd/pull/10782
dlang/dmd pull request #10782 "fix Issue 15812 - static struct inside extern(C++) class cannot be us…" was merged into master: - 143f827c04b2d9ce1e3969bb267f0173a635d17c by Walter Bright: fix Issue 15812 - static struct inside extern(C++) class cannot be used as key to associative array https://github.com/dlang/dmd/pull/10782