[dmd-beta] D2 2.058 beta

Martin Nowak dawg at dawgfoto.de
Sat Feb 11 02:57:13 PST 2012


// I.
void foo(V)(in V v)
{
}

// II.
void foo(Args...)(auto ref const Args args)
{
     foo(args[0]);
}

void main()
{
     foo(10);
}

-----

Deducing foo(10)
function arguments: rvalue int
I.  - MATCHconst
II. - MATCHexact

picks II

-----

Deducing foo(args[0])
function arguments: lvalue const(int)
I.  - MATCHexact
II. - MATCHexact

This is further disambiguated by leastAsSpecialized.
template.c(895):
         /* A non-variadic template is more specialized than a
          * variadic one.
          */
         if (isVariadic() && !td2->isVariadic())

picks I

-----

We end up instantiating both functions with the same argument types.
Thus the mangling is the same and the linker will pick whatever he likes.

1. I think that variadic templates shouldn't be exact matches.
2. We shouldn't use tiebreakers but issue ambiguous errors.

A quick fix would be to change variadic templates to MATCHconvert as in  
the attached patch.
But I think we should reduce the complexity of template matching rather  
than patching it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-use-MATCHconvert-for-variadic-templates.patch
Type: application/octet-stream
Size: 1107 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/dmd-beta/attachments/20120211/a51c013a/attachment.obj>


More information about the dmd-beta mailing list