On 02.10.2016 13:27, Manu via Digitalmars-d wrote:
And what's the logic behind this:

class Test
{
  int f() { return 10; }

  static assert(is(typeof(&typeof(this).f) == int function())); // huh?

  static void t()
  {
    // as expected:
    f(); // error : need 'this' for 'f' of type 'int()'

    // calling a method without a context pointer...
    auto x = &f;
    x(); // call the method with no context pointer, how is this okay?

    pragma(msg, typeof(x)); // prints: int function()
  }
}

If f() were supplied an argument, the function would receive the first
arg as the context pointer, and the rest would be out by 1! O_o
I don't see how this code can be acceptable?

If such a thing (getting a static function pointer from a delegate)
were to be supported, surely: is(typeof(&Test.f) == int
function(Test)), though this is only valid for some (most) abi's.

This is a known issue: https://issues.dlang.org/show_bug.cgi?id=3720

(What I do is: typeof(&typeof(this).f) is int delegate(), but auto x = &f does not compile as the 'this' reference is missing.)

Reply via email to