Bug 15812 – static struct inside extern(C++) class cannot be used as key to associative array

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-19T09:19:28Z
Last change time
2020-02-12T06:02:31Z
Keywords
C++, pull
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2016-03-19T09:19:28Z
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.
Comment #1 by moonlightsentinel — 2020-01-11T23:01:52Z
Comment #2 by bugzilla — 2020-02-12T04:20:09Z
It will work if toHash() is declared as extern (D).
Comment #3 by dlang-bot — 2020-02-12T04:27:21Z
@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
Comment #4 by dlang-bot — 2020-02-12T06:02:31Z
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