www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - typesafe variadic with default args


This doesn't make a whole lot of sense:

void foo(int arg1 = 0, int[] arg2...)

Error: default argument expected for arg2

The default argument is nothing, like normal, no? I'll note that 
non-typesafe variadic works.

In any case, there is something that *does* work, but it's hideous, and 
doesn't seem to be supported by the grammar:

void foo(int arg1 = 0, int[] arg2 = null...)


1. why is original not accepted? This seems like a no-brainer rejects-valid.
2. What is the second one? Is it accepts-invalid, or just not properly 
3. If 2 is accepts-invalid, will we break code by disabling it? Is it 
worth disabling?

A bizarre consequence of the accepted version is you could have a 
default argument that's larger than a specified argument:

void foo(int[] arg = [1,2,3]...)

void main()
    foo(); // equivalent to foo(1,2,3)
    foo(1); // less args than foo() !

Jun 04 2015