On 27 August 2012 16:23, kenji hara <k.hara.pg@gmail.com> wrote:
I think that the function type and its mangled name must not contain
the default args, then I can agree with Walter at the point.

But, I think the variables of function pointers and delegates still
can have default args as a part of their declarations.
(It will be a part of VarDeclaration, not a part of TypeFunction)
In following case, the default arg looks like a part of the type, but
actually is a part of the declaration of fp.

void function(int n = 10) fp;
pragma(msg, typeof(fp));  // should print void function(int), because
default args are not a part of type.
fp();  // I think this can be allowed, because fp can remember that
the first parameter has the default argument.

But, it seems to me there are some corner cases.

  // fp will *inherit* default args from its initializer, or not?
  auto fp = (int n = 10){}

I'd say, will.

  // what is the actual default arg of fp?
  void function(int n = 10) fp1 = (int n = 20){}
  void function(int n) fp2 = (int n = 30){}
  void function(int n = 40) fp3 = (int n){}

The declaration (on the left) is correct in all cases. It was explicitly stated when defining the variable.

  // fp has ambiguous default arg, or has no default arg?
  auto fp1 = some_runtime_condition ? (int n = 10){} : (int n = 20){} ;

Finally, a REAL conundrum! :) .. Not sure what to tell you... Error? Warning, and remove the default arg since there's a disagreement?
 
  // more complicated case, first defarg is same, then it will be *inherited*?
  auto fp2 = some_runtime_condition ? (int n = 10, string s =
"hello"){} : (int n = 10, string s = "world"){} ;

Same problem as above. I'd say hard error, since this is a) extremely unlikely! And b) it's obvious there's no 'correct' conclusion anyway.
The user writing that code clearly imagines that D is a dynamic language, and doesn't properly understand the nature of a compiled language.

  int function(int n = 10) fp;   // default arg of the first parameter is 10
  fp = (int n = 20){ return n; }  // function literal's default arg
will be ignored (in my opinion), is this expected?

Agree, the variable was already defined by the users explicit request.

  // returning function pointer/delegate type can have default args?
  int delegate(int n = 10) foo(int x) { ... }

Sure, why not? If the recipient is auto, then it should inherit those properties.

If we can take agreements each other about them, it may be supported.

+1 for Kenji :)