title: Why C++ linker is silent about ODR violation?
body: <p>Let's consider some synthetic but expressive example. Suppose we have Header.h:</p>
  
  <p>Header1.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  // Define generic version
  template&lt;typename T&gt;
  inline void Foo()
  {
      std::cout &lt;&lt; "Generic\n";
  }
  </code></pre>
  
  <p>Header2.h</p>
  
  <pre><code>void Function1();
  </code></pre>
  
  <p>Header3.h</p>
  
  <pre><code>void Function2();
  </code></pre>
  
  <p>Source1.cpp</p>
  
  <pre><code>#include "Header1.h"
  #include "Header3.h"
  
  // Define specialization 1
  template&lt;&gt;
  inline void Foo&lt;int&gt;()
  {
      std::cout &lt;&lt; "Specialization 1\n";
  }
  
  void Function1()
  {
      Foo&lt;int&gt;();
  }
  </code></pre>
  
  <p>Later I or some else defines similar conversion in another source file.
  Source2.cpp</p>
  
  <pre><code>#include "Header1.h"
  
  // Define specialization 2
  template&lt;&gt;
  inline void Foo&lt;int&gt;()
  {
      std::cout &lt;&lt; "Specialization 2\n";
  }
  
  void Function2()
  {
      Foo&lt;int&gt;();
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "Header2.h"
  #include "Header3.h"
  
  int main()
  {
      Function1();
      Function2();
  }
  </code></pre>
  
  <p>The question is what will print Function1() and Function2()? The answer is undefined behavior.</p>
  
  <p>I expect to see in output: 
  Specialization 1
  Specialization 2</p>
  
  <p>But I see: 
  Specialization 2
  Specialization 2</p>
  
  <p>Why C++ compilers are silent about ODR violation? I would prefer compilation to be failed in this case.</p>
  
  <p>I found only one workaround: define template functions in unnamed namespace. </p>