www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3559] New: DMD 1.048+ fails to take function pointer from overloaded member functions

reply d-bugmail puremagic.com writes:
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: -------
Nov 30 2009
next sibling parent d-bugmail puremagic.com writes:
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: -------
Jan 12 2010
prev sibling parent d-bugmail puremagic.com writes:
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: -------
Jan 12 2010