Annotating const toHash methods with @disable causes unresolved symbol errors in the link stage. ``` struct X { @disable size_t toHash() const; } ``` will cause ``` onlineapp.o:onlineapp.d:_D22TypeInfo_S9onlineapp1X6__initZ: error: undefined reference to '_D9onlineapp1X6toHashMxFZm' ```
That has nothing to do with the @disable attribute. It's because you need to add a body to `toHash()`. Like this: ``` @disable size_t toHash() const { return 0; } ``` For the v2.091 of DMD: ``` struct X { @disable size_t toHash() const nothrow @safe { return 0; } } ```
Incorrect. a @disabled method does not need a body, as no references to it are ever emitted. You can observe this for yourself by simply renaming toHash in the example to something without special semantics. Or by removing const. Even a non-@disable'd method without a body doesn't generate linker errors unless you try to call it.
(In reply to elpenguino+D from comment #2) > Incorrect. a @disabled method does not need a body, as no references to it > are ever emitted. You can observe this for yourself by simply renaming > toHash in the example to something without special semantics. Or by removing > const. Even a non-@disable'd method without a body doesn't generate linker > errors unless you try to call it. You're right. That was a workaround :P This bug is also valid for `toString()`. ``` struct Foo { @disable size_t toHash() const nothrow @safe; // linker fail @disable size_t toHash(); // ok @disable string toString(); // linker fail } class Bar { @disable override size_t toHash() const nothrow @safe; // linker fail @disable override size_t toHash(); // linker fail @disable override string toString(); // linker fail } ```
@Geod24 created dlang/dmd pull request #14272 "Fix 18973 - TypeInfo generation does not account for `@disable`" fixing this issue: - Fix 18973 - TypeInfo generation does not account for `@disable` This changes `overloadExactMatch` as all 14 usages of it are to find functions that can later be called. https://github.com/dlang/dmd/pull/14272
dlang/dmd pull request #14272 "Fix 18973, 9161 - TypeInfo generation does not account for `@disable`" was merged into master: - 22e4aecb13b7020cbc4525e6eb0a4d77b7528d74 by Geod24: Fix 18973 - TypeInfo generation does not account for `@disable` This changes `overloadExactMatch` as all 14 usages of it are to find functions that can later be called. https://github.com/dlang/dmd/pull/14272