[Issue 3720] Taking address of member functions possible without an instance

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 4 11:01:22 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=3720

--- Comment #27 from Bolpat <qs.il.paperinik at gmail.com> ---
Given
```d
struct T
{
    ref int memFunc(return ref int i) return @safe immutable { return i; }
}
```
I guess the only reasonable thing `typeof(&T.memFunc)` could be is:
```d
ref int function(return ref immutable T, return ref int i) @safe
```

We can argue about whether the `T` parameter must be `ref`, but unless we have
a mechanism to express “bind by mutable reference irrespective of value
category” (this is how member functions bind the `this` object) as a parameter
storage class, the only option is `ref`. Copy isn’t an option, not all types
are copyable. `in` isn’t an option because it makes mutable objects `const`.

DMD’s answer for `typeof(&T.memFunc)` is nonsense:
```d
ref int function(return ref int i) immutable return @safe
```

Both, `immutable` and `return` make no sense on a function pointer type and do
not even parse.

--


More information about the Digitalmars-d-bugs mailing list