www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12773] New: Compiler implicitly converts delegate into


          Issue ID: 12773
           Summary: Compiler implicitly converts delegate into function
                    when taking an address of a method
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: andrej.mitrovich gmail.com

This is extremely nasty. Take a look:

alias Func = void function();

class C
    static void foo() { }
    void bar() { }

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;  // oops, we forgot to mark 'bar' as static!!
        func();  // access violation (requires 'this')

The current semantics force us to be extremely careful when using function
pointers. We should ban the implicit conversion of &foo to a function pointer
if this is really a non-static class method. People can use .funcPtr or some
other equivalent instead.

May 20 2014