title: Explicit Specialization of non-template member function is not called
body: <p>...unless something else from the library is called. Here is a minimal example. </p>
  
  <p>test1.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  void proofOfTwoLinked();
  
  template &lt;class T&gt;
  struct Foo
  {
      void bar(){ std::cout &lt;&lt; "normal bar\n"; }
  };
  
  struct A{};
  struct B{};
  struct C{};
  struct D{};
  
  template &lt;&gt; void Foo&lt;B&gt;::bar(){ std::cout &lt;&lt; "B bar\n"; }
  
  int main()
  {
      Foo&lt;A&gt; a;
      Foo&lt;B&gt; b;
      Foo&lt;C&gt; c;
      Foo&lt;D&gt; d;
  
      a.bar();
      b.bar();
      c.bar();
      d.bar();
  
      //proofOfTwoLinked();
  }
  </code></pre>
  
  <p>test2.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct C;
  
  template &lt;class T&gt;
  struct Foo
  {
      void bar(){ std::cout &lt;&lt; "normal bar\n"; }
  };
  
  template &lt;&gt; void Foo&lt;C&gt;::bar(){ std::cout &lt;&lt; "C bar\n"; }
  
  void proofOfTwoLinked()
  {
      std::cout &lt;&lt; "Yup, two is linked\n";
  }
  </code></pre>
  
  <p>If I compile the two together, the program works as expected:</p>
  
  <pre><code>$ rm test; rm *.a; rm *.o; g++ -c test1.cpp; g++ -c test2.cpp; g++ -o test test1.o test2.o; ./test
  normal bar
  B bar
  C bar
  normal bar
  </code></pre>
  
  <p>If I compile test2, put it in an archive, and then link the program against that... the specialization for type C is not executed when c.bar() is called:</p>
  
  <pre><code>$ rm test; rm *.a; rm *.o; g++ -c test1.cpp; g++ -c test2.cpp; ar -r test2.a test2.o; g++ -o test test1.o test2.a; ./test
  ar: creating test2.a
  normal bar
  B bar
  normal bar
  normal bar
  </code></pre>
  
  <p>But if I uncomment the last function call of test1 (proofOfTwoLinked) and then compile again, the specialization <em>is</em> executed. </p>
  
  <pre><code>$ rm test; rm *.a; rm *.o; g++ -c test1.cpp; g++ -c test2.cpp; ar -r test2.a test2.o; g++ -o test test1.o test2.a; ./test
  ar: creating test2.a
  normal bar
  B bar
  C bar
  normal bar
  Yup, two is linked
  </code></pre>
  
  <p>This strikes me as weird, and is certainly contrary to my expectation. Is this in fact normal behavior? Perhaps since there already exists some form of every function that is called in main() before the linker searches test2.a it skips the archive. Is there a way to force the linker to "look at the whole archive"?</p>
  
  <p>I'm using gcc 4.6.1 and ar 2.21.53 (in ubuntu). </p>