Hi all, I am aware of the nonsensical delegate -> function conversion
sequence for non-static member functions, as demonstrated by
```d
class Class { int doubling(int x) { return x * 2; } }
void main()
{
int function(int) fptr = &Class.doubling; // typechecks!
}
```
However, there is some deeper unsound compiler reasoning going on.
Consider
```d
// vvvvv notice the member fn attribute
class Class { int doubling(int x) inout { return x * 2; } }
void main()
{
int function(int) fptr = &Class.doubling;
}
```
dmd fails with
> Error: cannot implicitly convert expression `& doubling`
of type `int function(int x) inout` to `int function(int)`
Adjust the type of fptr it shall be then. Alas... no.
```d
[...]
void main()
{
int function(int) inout fptr = &Class.doubling;
}
```
fails with
> Error: `const`/`immutable`/`shared`/`inout`/`return` attributes
are only valid for non-static member functions
But when done with `auto`, it says
```d
[...]
void main()
{
auto fptr = &Class.doubling;
pragma(msg, typeof(fptr)); // int function(int) inout
}
```
What gives?
Comment #1 by robert.schadek — 2024-12-13T19:21:57Z