D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3559 - DMD 1.048+ fails to take function pointer from overloaded member functions
Summary: DMD 1.048+ fails to take function pointer from overloaded member functions
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: yebblies
URL:
Keywords: pull, rejects-valid, wrong-code
: 4860 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-11-30 08:08 UTC by David Nadlinger
Modified: 2015-06-09 05:11 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Nadlinger 2009-11-30 08:08:06 UTC
The following code compiles and works fine on DMD 1.047 and older (DMD 1.023 was the earliest one I tested), but no longer compiles with DMD 1.048 up to DMD 1.052 because the compiler cannot »choose« the correct overload when it tries to create the delegate/function pointer. In older versions, the casts were enough of a hint.

Note, however, that the code compiles without any errors if the overload I try to get the address of is the last one declared – in the example below, getting the address of »void foo( float a )« would work fine.

---

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

class A {
  void foo( float a ) {}
  void foo( int a ) {}

  void bar() {
    void* dg = addressOf!( foo, void function( float ) );
    auto blah = cast( void delegate( float ) )&foo;
    if ( cast( void* )blah.funcptr == dg ) {
      // Stdout( "not overridden" ).newline;
    } else {
      // Stdout( "overridden" ).newline;
    }
  }
}

class B : A {
  override void foo( float a ) {}
  override void foo( int a ) {}
}

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

  A b = new B();
  b.bar;
}
Comment 1 Don 2010-01-12 02:55:45 UTC
(In reply to comment #0)
> The following code compiles and works fine on DMD 1.047 and older (DMD 1.023
> was the earliest one I tested), but no longer compiles with DMD 1.048 up to DMD
> 1.052 because the compiler cannot »choose« the correct overload when it tries
> to create the delegate/function pointer. In older versions, the casts were
> enough of a hint.

This is because bug 52 was fixed. The compiler used to accept all kinds of garbage.
Comment 2 David Nadlinger 2010-01-12 03:33:06 UTC
(In reply to comment #1)
> This is because bug 52 was fixed. The compiler used to accept all kinds of
> garbage.

If I am not misunderstanding you and the snippet I posted is in fact invalid code (it looks very strange indeed, but this is the only working version I and the folks at #d could come up with), there are now two seperate issues:

Firstly, this bug should in fact be an »accepts-invalid« one, since it compiles if you put the function declarations in a certain order (see the original report).

Secondly, there really ought to be a way to get this check to work for *both* overloaded and non-overloaded functions – or neither of them. With my language designer as well as my developer hat on, the restriction to non-overloaded functions is a rather annoying shortcoming…
Comment 3 yebblies 2012-02-11 21:01:49 UTC
*** Issue 4860 has been marked as a duplicate of this issue. ***
Comment 5 github-bugzilla 2012-02-19 16:31:28 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/35c67b1229306f0006209db21e34bd6d406136d7
Merge pull request #711 from yebblies/issue3559

Issue 3559 - DMD 1.048+ fails to take function pointer from overloaded member functions
Comment 6 github-bugzilla 2012-02-19 20:47:40 UTC
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b53732624fbb70a3e648f923384cf107915d8159
fix Issue 3559 - DMD 1.048+ fails to take function pointer from overloaded member functions