Thread overview
[Issue 3559] New: DMD 1.048+ fails to take function pointer from overloaded member functions
Jan 12, 2010
Don
Feb 12, 2012
yebblies
Feb 12, 2012
yebblies
Feb 20, 2012
Walter Bright
November 30, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3559

           Summary: DMD 1.048+ fails to take function pointer from
                    overloaded member functions
           Product: D
           Version: 1.051
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: klickverbot@gmail.com


--- Comment #0 from klickverbot@gmail.com 2009-11-30 08:08:06 PST ---
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;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3559


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2010-01-12 02:55:45 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3559



--- Comment #2 from klickverbot@gmail.com 2010-01-12 03:33:06 PST ---
(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…

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3559



--- Comment #3 from yebblies <yebblies@gmail.com> 2012-02-12 16:01:49 EST ---
*** Issue 4860 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3559


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, wrong-code
                 CC|                            |yebblies@gmail.com
            Version|1.051                       |D1 & D2
         AssignedTo|nobody@puremagic.com        |yebblies@gmail.com


--- Comment #4 from yebblies <yebblies@gmail.com> 2012-02-12 16:13:31 EST ---
https://github.com/D-Programming-Language/dmd/pull/711

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3559



--- Comment #5 from github-bugzilla@puremagic.com 2012-02-19 16:31:28 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3559



--- Comment #6 from github-bugzilla@puremagic.com 2012-02-19 20:47:40 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3559


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------