Thread overview
[Issue 2803] New: template + default argument = doesn't work
Apr 05, 2009
d-bugmail
Apr 06, 2009
d-bugmail
Apr 15, 2013
Martin Nowak
April 05, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2803

           Summary: template + default argument = doesn't work
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: andrei@metalanguage.com


struct S {}
ref S getS();

void fun(T, U)(T t, ref U u = getS)
{
}

void main()
{
    fun(1);
}

./test.d(10): Error: template test.fun(T,U) does not match any function
template declaration
./test.d(10): Error: template test.fun(T,U) cannot deduce template function
from argument types !()(int)


-- 

April 06, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2803


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
         OS/Version|Linux                       |All




------- Comment #1 from smjg@iname.com  2009-04-05 19:00 -------
I'm not sure that this is supposed to work.  It would appear that the process of binding template parameters to arguments happens strictly before that of applying default arguments.  Moreover, even if U is given, if it's anything but S then it triggers a type mismatch on the default argument.

It would appear that you need two templates

void fun(T)(T t)
{
    fun(t, getS());
}

void fun(T, U)(T t, U u)
{
}


-- 

April 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=2803


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu


--- Comment #2 from Martin Nowak <code@dawg.eu> 2013-04-14 22:56:07 PDT ---
To me it looks like it should work. When the arity requires it, the default argument should be added to the list of function arguments before deducing the template arguments.

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