Bug 18973 – @disable on const toHash causes unresolved symbol error
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-06-12T08:56:25Z
Last change time
2022-07-07T10:16:21Z
Keywords
link-failure, pull, rejects-valid
Assigned to
No Owner
Creator
elpenguino+D
Comments
Comment #0 by elpenguino+D — 2018-06-12T08:56:25Z
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'
```
Comment #1 by lucien.perregaux — 2020-05-09T15:24:04Z
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;
}
}
```
Comment #2 by elpenguino+D — 2020-05-09T19:13:50Z
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.
Comment #3 by lucien.perregaux — 2020-05-09T21:28:09Z
(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
}
```
Comment #4 by dlang-bot — 2022-07-07T04:41:16Z
@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
Comment #5 by dlang-bot — 2022-07-07T10:16:21Z
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