On Saturday, 25 August 2018 at 01:43:19 UTC, Walter Bright wrote:
On 8/24/2018 4:22 PM, tide wrote:
struct SomeStruct
{
     void foo() {
         // use SomeStruct
     }
}


void broken()
{
     void function() foo = &SomeStruct.foo;
    foo(); // runtime error, isn't actually safe uses wrong calling convention as well
}

Not really lack of feature so much as there exists broken code. This has been valid code for god knows how long. At some point it was usable in @safe, but it looks you can't take an address of a member function without "this" as well in safe anymore.


That's because it isn't safe. But being able to take the address is important for system work.

The stupid thing is you _have_ to cast (which is unsafe) the return type to be correct.

This could be solvable with DIP1011 to make &SomeStruct.foo return `extern(delegate) void function(ref Foo)` although it makes no explicit mention other than "member functions be implicitly convertible to extern(delegate) functions".

Reply via email to