D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15812 - static struct inside extern(C++) class cannot be used as key to associative array
Summary: static struct inside extern(C++) class cannot be used as key to associative a...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: C++, pull
Depends on:
Blocks:
 
Reported: 2016-03-19 09:19 UTC by Walter Bright
Modified: 2020-02-12 06:02 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2016-03-19 09:19:28 UTC
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 moonlightsentinel 2020-01-11 23:01:52 UTC
Introduced in https://github.com/dlang/dmd/pull/3054
Comment 2 Walter Bright 2020-02-12 04:20:09 UTC
It will work if toHash() is declared as extern (D).
Comment 3 Dlang Bot 2020-02-12 04:27:21 UTC
@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 Dlang Bot 2020-02-12 06:02:31 UTC
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