Bug 8430 – [2.060 beta] Default arguments ignored for delegates/function pointers

Status
RESOLVED
Resolution
DUPLICATE
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-24T22:48:00Z
Last change time
2012-07-24T23:01:48Z
Assigned to
nobody
Creator
sludwig

Comments

Comment #0 by sludwig — 2012-07-24T22:48:25Z
The following used to work in 2.059. Not sure if default args are supposed to work at all, but in case they are not, they should not be accepted at declaration site in the first place. --- void main() { void delegate(int arg = 0) del; del(); // error void function(int arg = 0) fun; fun(); // error } --- delegate_defarg.d(4): Error: expected 1 function arguments, not 0 delegate_defarg.d(7): Error: expected 1 function arguments, not 0
Comment #1 by issues.dlang — 2012-07-24T22:56:27Z
They shouldn't be accepted at the declaration site. Default arguments for function pointers and delegates make no sense. The only time that default function arguments are used is when you call a function by its name and you don't give all of the arguments, in which case the default arguments are effectively copy-pasted at the call site. As function pointers and delegates aren't named (variables referring to them may be, but they themselves aren't), and default arguments aren't part of a function's type, there's no way to call them with default arguments without the compiler special casing situations like the one that you give here. Now, even given all of that, I don't think that this is a regression. The fact that it complains at the call site and didn't before is a bug fix, not a bug. And it's never complained at the declaration site, so not complaining is exactly what it's been doing, so it can't be a regression even though it's a bug.
Comment #2 by bugzilla — 2012-07-24T23:01:48Z
See the discussion for bug 3866. *** This issue has been marked as a duplicate of issue 3866 ***