www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8336] New: Default function parameters ignored by delegate

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8336

           Summary: Default function parameters ignored by delegate
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: puneet coverify.org



---
This code worked for version 2.059. But with the latest git pull, it does not
compile, saying:
test.d(5): Error: expected 1 function arguments, not 0


void callfoo(alias F, T) (T t) {
  typeof(&Foo.init.foo) dg;
  dg.funcptr = &F;
  dg.ptr = cast(void *)t;
  dg();
}

class Foo {
  void foo(int n=2) {}
}

void main() {
  Foo f = new Foo();
  callfoo!(Foo.foo)(f);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8336


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



Default arguments were never reliable for functions called trough a pointer, so
this little change is expected, take a look at the changelog of 2.060alpha. I
suggest to close this bug report...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8336




---
 Default arguments were never reliable for functions called trough a pointer, so
 this little change is expected, take a look at the changelog of 2.060alpha.
I think it would be cool if default arguments could be maintained for corresponding delegates too. I am too naive right now to find out which entry in the changelog are you pointing too. I tried but could not find anything obvious (to me). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 02 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8336


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jmdavisProg gmx.com
         Resolution|                            |DUPLICATE



PDT ---
Given how default arguments work, they make _no_ sense for either function
pointers or delegates. All that happens with a default argument is that when
you call the function, if you don't provide a value for the parameter with a
default argument, the default argument is inserted for you. It's not part of
the function's type. It doesn't result in multiple functions being declared.
So, if you do

void foo(int value = 5) {...}
auto funcPtr = &foo;

you've lost the information about the default argument. You simply have

void function(int value) funcPtr;

You could reassign it like so

void bar(int number) {... }
funcPtr = &bar;

because the types are identical. The default argument has zero effect on the
type. The situation does not change if you're dealing with a delegate rather
than a function pointer. Function pointers and delegates just don't have
anything to do with default arguments.



shouldn't due to issues with default arguments.

*** This issue has been marked as a duplicate of issue 3646 ***

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