[Issue 8687] Variadic templates do not work properly with default arguments

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Apr 18 03:09:25 PDT 2017


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

Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang at jmdavisProg.co
                   |                            |m

--- Comment #4 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
It looks like the status quo right now (with the development version of dmd
2.075) is that default arguments work with variadic templates if the template
is explicitly instantiated but not if IFTI is used. So,

-----
void foo(T...)(T args, string file = __FILE__) { }

void main()
{
    foo();
}
-----

won't compile, but

-----
void foo(T...)(T args, string file = __FILE__) { }

void main()
{
    foo!int(42);
}
-----

will. So, it looks like this is probably now purely an IFTI issue. And
presumably, IFTI could be made to just assume that the default arguments are
always used (since it has no way of differentiating between explicit arguments
for those parameters and variadic arguments that have the same type, and anyone
who wants to provid explicit arguments can always explicitly instantiate the
template, which even works right now). That _seems_ like it would be
straightforward, but I'm not at all familiar with how IFTI is implemented in
the compiler.

Regardless, having it fixed so that the default arguments compile when IFTI is
used would have a significant impact on stuff like std.experimental.logger,
which currently has __FILE__, __LINE__, __FUNCTION__, __PRETTY_FUNCTION__, and
__MODULE__ as default template arguments, which results in a function template
being instantiated for every log call.

--


More information about the Digitalmars-d-bugs mailing list