title: competing implicit and template copy constructors
body: <p>In relation to <a href="https://stackoverflow.com/questions/1249814/templated-copy-constructor-fails-with-specific-templated-type">this</a> post, please explain this behavior: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  struct B { B(B&amp;) { } B() { } };
  struct A {
    template&lt;typename T&gt;
    A(T&amp;){ printf("A(T&amp;)\n"); }
    A() { }
  //  B b; // when this is uncommented, output changes 
    int i;
  };
  
  int main() {
    A a;
    A b(a);
  
  // B b; commented:
  // template wins:
  //   A&lt;A&gt;(A&amp;)  -- specialization
  //   A(A const&amp;); -- implicit copy constructor
  // (prefer less qualification)
  
  // B b; uncommented:
  // implicit copy constructor wins:
  //   A&lt;A&gt;(A&amp;)  -- specialization
  //   A(A&amp;); -- implicit copy constructor
  // (prefer non-template)
  
    printf("\nA\n");
    A const a1;
    A b1(a1);
  
  // B b; commented:
  // implicit copy constructor wins: 
  //   A(A const&amp;) -- specialization
  //   A(A const&amp;) -- implicit copy constructor
  // (prefer non-template)
  
  // B b; uncommented:
  // template wins:
  //   A(A const&amp;) -- specialization
  // (implicit copy constructor not viable)
  }
  </code></pre>
  
  <p>Output changes when B b; is uncommented. </p>
  
  <p>Apparently, the implicit copy constructor changes from <code>A(A const&amp;)</code> to <code>A(A &amp;)</code> when <code>B b;</code> is uncommented. Why? When I change <code>B(B&amp;){}</code> to <code>B(const B&amp;){}</code> the  copy constructor changes back to <code>A(A const&amp;)</code>. Now the compiler is satisfied that the formal parameter of <code>A()</code> will be <code>const</code>? Does this have anything to do with the standard? (I'm using gcc 4.2.4.) </p>