While compiling some C++11 code with both GCC 4.7.2 and Clang 3.1, I ran into a problem with Clang not managing to deduce a template argument where GCC succeeds. In a more abstr
Clang is trying to deduce the arguments for this call:
processVariadic(SecondContainer<Element>{});
Since SecondContainer
has a default template argument, this is equivalent to:
processVariadic(SecondContainer<Element, Element>{});
Thus, it performs template argument deduction with P
= Container<Element>
and A
= SecondContainer<Element, Element>
. It can immediately deduce that the Container
template parameter is SecondContainer
.
Next, it considers the template arguments. Since the argument type is fully resolved, Clang believes that the parameter must have as many types, or deduction cannot possibly succeed (it doesn't take default arguments into account). So it flags a deduction failure.
So, what's supposed to happen? In the words of [temp.deduct.type]p8
,
A template type argument
T
, a template template argumentTT
or a template non-type argument i can be deduced ifP
andA
have one of the following forms:
[...]
TT<T>
TT<i>
TT<>
where [...]<T>
represents template argument lists where at least one argument contains aT
,<i>
represents template argument lists where at least one argument contains ani
and<>
represents template argument lists where no argument contains aT
or ani
.
In order to match the template arguments, we turn to [temp.deduct.type]p9
:
If
P
has a form that contains<T>
or<i>
, then each argumentPi
of the respective template argument listP
is compared with the corresponding argumentAi
of the corresponding template argument list ofA
.
There are two things to observe here. One is that this rule does not say what happens if the list Pi
and Ai
are different lengths (as they are in this case), and the common interpretation seems to be that the mismatched items are not examined. The other is that this rule should not be followed anyway, since the form of P
does not contain <T>
or <i>
(it just contains <>
, because there are no template parameters in it).
So, Clang was wrong to reject this code. I've fixed it in r169475.