[Issue 3646] Default values of function arguments are ignored when instantiating a template.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 25 08:32:34 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3646


Koroskin Denis <2korden at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |2korden at gmail.com


--- Comment #1 from Koroskin Denis <2korden at gmail.com> 2009-12-25 08:32:32 PST ---
This is a bit more tricky than it looks like.

The question here is, how many times should foo be instanciated?
DMD answers "just 1 time", and I agree with it, since bar and bam have same
signature and mangling.

Having only one instantiation means that code for it will also be generated
once.

When you call a function that has default argument without providing that
argument, the call is actually *rewritten to include that argument*. I.e.
bar(); is rewritten as bar(22);

Not lets see how foo!(bar) looks like after a rewrite:

void foo(Fn)(Fn fn)
{
    fn(22);
}

Now there is no wonder why dmd behaves like this.

But this only happens if foo!(bar) is instanciated before foo!(bam), because
when templates are instantiates on first use. When you instanciate foo!(bam)
first, it doesn't get rewritten and therefore fails to compile.

I guess the only fix for this issue would be to create an implicit trampoline
to invoke functions with default arguments, but only Walter can say for sure.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list