Thread overview
[Issue 12773] Compiler implicitly converts delegate into function when taking an address of a method
Jun 04, 2014
Orvid King
Nov 30, 2014
nick
Dec 31, 2014
yebblies
June 04, 2014
https://issues.dlang.org/show_bug.cgi?id=12773

--- Comment #1 from Orvid King <blah38621@gmail.com> ---
I suspect you meant to suggest removing the implicit conversion of &C.bar (a delegate) to a function pointer. I would agree with this, and am extremely surprised this is allowed in the first place. Perhaps it was an attempt to implement implicit conversion from a function pointer to a delegate? (which does make sense to be possible)

--
November 30, 2014
https://issues.dlang.org/show_bug.cgi?id=12773

nick <nicolas.jinchereau@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nicolas.jinchereau@gmail.co
                   |                            |m

--- Comment #2 from nick <nicolas.jinchereau@gmail.com> ---
I believe this behaviour is by design. There is no implicit conversion, because &C.bar is not a delegate, it is a function pointer. The following code works as expected:


alias Func = void function();
alias Del = void delegate();

class C
{
    string str = "bar";
    static void foo() { }
    void bar() { writeln(str); }
}

void main()
{
    {
        // Func func = C.foo;  // disallowed, since this is a function call
    }

    {
        Func func = &C.foo;  // ok, the proper syntax usage.
        func();  // ok
    }

    {
        Func func = &C.bar;  // correct

        C c = new C;
        Del del = &c.bar;    // correct

        Del del2;
        del2.funcptr = func;
        del2.ptr = cast(void*)c;
        del2();               // works, output is "bar"
    }
}

--
December 31, 2014
https://issues.dlang.org/show_bug.cgi?id=12773

yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies@gmail.com
         Resolution|---                         |DUPLICATE

--- Comment #3 from yebblies <yebblies@gmail.com> ---
An old favorite.

*** This issue has been marked as a duplicate of issue 3720 ***

--