Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #381 (new defect)

Opened 2 years ago

»need 'this'« error when taking the address of a member function at compile time

Reported by: klickverbot Assigned to: lindquist
Priority: major Milestone:
Component: frontend (D1 only) Version: hg tip
Keywords: Cc:

Description

The following code compiles and works using DMD 1.051. When trying to compile with LDC, I get Error: need 'this' to access foo pointing to the cost line in the template.

The test case triggering the error:

template addressOf( alias fn ) {
  const addressOf = &fn;
}

class A {
  void foo() {}

  final void bar() {
    auto dg = &foo;
    if ( addressOf!( foo ) == dg.funcptr ) {
      Stdout( "not overridden" ).newline;
    } else {
      Stdout( "overridden" ).newline;
    }
  }
}

class B : A {
  override void foo() {}
}

void main() {
  A a = new A();
  a.bar;

  A b = new B();
  b.bar;
}
Copyright © 2008, LDC Development Team.