title: Ambiguous operator overload in Clang
body: <p>Consider the following:</p>
  
  <pre><code>template&lt;typename T&gt;
  struct C {};
  template&lt;typename T, typename U&gt;
  void operator +(C&lt;T&gt;&amp;, U);
  
  struct D: C&lt;D&gt; {};
  
  struct E {};
  template&lt;typename T&gt;
  void operator +(C&lt;T&gt;&amp;, E);
  
  void F() { D d; E e; d + e; }
  </code></pre>
  
  <p>This code compiles fine on both GCC-7 and Clang-5. The selected overload for <code>operator +</code> is that of <code>struct E</code>.</p>
  
  <p>Now, if the following change takes place:</p>
  
  <pre><code>/* Put `operator +` inside the class. */
  template&lt;typename T&gt;
  struct C {
      template&lt;typename U&gt;
      void operator +(U);
  };
  </code></pre>
  
  <p>that is, if <code>operator +</code> is defined <em>inside</em> the class template, instead of <em>outside</em>, then Clang yields ambiguity between both <code>operator +</code>s present in the code. GCC still compiles fine.</p>
  
  <p>Why does this happen? Is this a bug in either GCC or Clang?</p>