[Issue 19057] 2.079 changelog variadic template and default arguments

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 5 20:50:41 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19057

--- Comment #6 from Steven Schveighoffer <schveiguy at yahoo.com> ---
OK, I misunderstood. So essentially, any function that uses variadic parameters
AND a normal parameter with a default value was EXACTLY the same as a function
which takes the varargs parameter and a normal parameter WITHOUT a default
value prior to 2.079.

i.e. ALL code that uses default parameters after varargs parameters can be
rewritten to simply remove the default parameter, and the same behavior
occurred

But in addition, there is a strange new behavior that has default parameters
NEVER match the parameters unless you disable IFTI.

Indeed I find it odd that this would be the case:

void foo(A...)(A a, int timeout) {}
void bar(A...)(A a, int timeout = 0) {}

foo(1); // equivalent to foo!()(1)
bar(1); // equivalent to bar!(int)(1, 0) ???

Given the use case of file and line parameters, this makes sense, as you almost
never want to pass those parameters. But in the general case it makes very
little sense.

I'm pretty sure phobos was changed to take advantage of this immediately. So
reverting would be really painful, right?

If I were to start over before 2.079, this is the path I would have taken:

1. Make default parameters in these cases actually work in the way we would
expect (i.e. they match if they are the right type, otherwise they go to the
variadic).
2. Fix issue 18919
3. Create a new type `Location`, which accepts a filename and line number, and
use THAT as the final parameter for such functions, with a default value of
Location loc = Location(__FILE__, __LINE__). Now, you would never
"accidentally" pass in a file or line number.

I don't know the path forward now...

--


More information about the Digitalmars-d-bugs mailing list