title: Template partial ordering - why does partial deduction succeed here
body: <p>Consider the following simple (to the extent that template questions ever are) example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  struct identity;
  
  template &lt;&gt;
  struct identity&lt;int&gt; {
      using type = int;
  };
  
  template&lt;typename T&gt; void bar(T, T ) { std::cout &lt;&lt; "a\n"; }
  template&lt;typename T&gt; void bar(T, typename identity&lt;T&gt;::type) { std::cout &lt;&lt; "b\n"; }
  
  int main ()
  {
      bar(0, 0);
  }
  </code></pre>
  
  <p>Both clang and gcc print "a" there. According to the rules in [temp.deduct.partial] and [temp.func.order], to determine partial ordering, we need to synthesize some unique types. So we have two attempts at deduction: </p>
  
  <pre><code>+---+-------------------------------+-------------------------------------------+
  |   | Parameters                    | Arguments                                 |
  +---+-------------------------------+-------------------------------------------+
  | a | T, typename identity&lt;T&gt;::type | UniqueA, UniqueA                          |
  | b | T, T                          | UniqueB, typename identity&lt;UniqueB&gt;::type |
  +---+-------------------------------+-------------------------------------------+
  </code></pre>
  
  <p>For deduction on "b", according to <a href="https://stackoverflow.com/a/1193395/2069064">Richard Corden's answer</a>, the expression <code>typename identity&lt;UniqueB&gt;::type</code> is treated as a type and is not evaluated. That is, this will be synthesized as if it were:</p>
  
  <pre><code>+---+-------------------------------+--------------------+
  |   | Parameters                    | Arguments          |
  +---+-------------------------------+--------------------+
  | a | T, typename identity&lt;T&gt;::type | UniqueA, UniqueA   |
  | b | T, T                          | UniqueB, UniqueB_2 |
  +---+-------------------------------+--------------------+
  </code></pre>
  
  <p>It's clear that deduction on "b" fails. Those are two different types so you cannot deduce <code>T</code> to both of them.</p>
  
  <p>However, it seems to me that the deduction on <code>A</code> should fail. For the first argument, you'd match <code>T == UniqueA</code>. The second argument is a non-deduced context - so wouldn't that deduction succeed iff <code>UniqueA</code> were convertible to <code>identity&lt;UniqueA&gt;::type</code>? The latter is a substitution failure, so I don't see how this deduction could succeed either. </p>
  
  <p>How and why do gcc and clang prefer the "a" overload in this scenario?</p>