https://issues.dlang.org/show_bug.cgi?id=19239
Issue ID: 19239 Summary: Fix unsafe casting away of const in hashOf(const Object) Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: druntime Assignee: nob...@puremagic.com Reporter: n8sh.second...@hotmail.com `Object.toHash` is not const. Since a struct's `toHash` needs to be const, usually a struct will just cast away const-ness of an Object and hope that this violation of the type system doesn't cause a catastrophe. This happens to be okay for objects that don't override `toHash` because the base implementation is based on the object's address and is logically const even though it doesn't have the `const` attribute. We can make this sound by performing a runtime check to see if it uses the address-based Object.toHash. (It would be even better if we could perform a runtime check to see if its overridden with a const function, but I don't believe that is a way to do this.) Doing this will let us legitimately call `const(Object).toHash()` in `@trusted` code. --