title: ODR of template class with static constexpr member
body: <p>I know, there are many answered question about linkage of a static (constexpr) members.</p>
  
  <p>But I wonder, why using a template class out-of-line definition works in a header file but not for a specialized class.</p>
  
  <p>a) This works without linker error:</p>
  
  <pre><code>template&lt;typename, typename&gt;
  struct Foobar;
  
  template&lt;typename T&gt;
  struct Foobar&lt;int, T&gt; {
    static constexpr std::array&lt;int, 1&gt; a = {{1}};
  };
  
  template&lt;typename T&gt;
  constexpr std::array&lt;int, 1&gt; Foobar&lt;int, T&gt;::a;
  
  // foo.cpp
  std::cout &lt;&lt; Foobar&lt;int, int&gt;::a[0] &lt;&lt; "\n";
  
  // bar.cpp
  std::cout &lt;&lt; Foobar&lt;int, int&gt;::a[0] &lt;&lt; "\n";
  </code></pre>
  
  <p>The objdump of:</p>
  
  <p>foo.o: <code>0000000000000000  w    O .rodata._Z6FoobarIiiE1aE    0000000000000004 _Z6FoobarIiiE1aE</code></p>
  
  <p>bar.o: <code>0000000000000000  w    O .rodata._Z6FoobarIiiE1aE    0000000000000004 _Z6FoobarIiiE1aE</code></p>
  
  <p>Linked file: <code>0000000000475a30  w    O .rodata  0000000000000004 _Z6FoobarIiiE1aE</code></p>
  
  <p>b) This does not (multiple definition):</p>
  
  <pre><code>template&lt;typename&gt;
  struct Foobar;
  
  template&lt;&gt;
  struct Foobar&lt;int&gt; {
    static constexpr std::array&lt;int, 1&gt; a = {{1}};
  };
  constexpr std::array&lt;int, 1&gt; Foobar&lt;int&gt;::a;
  
  // foo.cpp
  std::cout &lt;&lt; Foobar&lt;int&gt;::a[0] &lt;&lt; "\n";
  
  // bar.cpp
  std::cout &lt;&lt; Foobar&lt;int&gt;::a[0] &lt;&lt; "\n";
  </code></pre>
  
  <p>The objdump of:</p>
  
  <p>foo.o <code>0000000000000100 g     O .rodata        0000000000000004 _Z6FoobarIiE1aE</code></p>
  
  <p>bar.o: <code>0000000000000420 g     O .rodata        0000000000000004 _Z6FoobarIiE1aE</code></p>
  
  <p>What we see, the out-of-line definition has different addresses inside the object files (example b)).</p>
  
  <p>My question to you:</p>
  
  <ol>
  <li>Is it save to use the template trick? What are the disadvantage?</li>
  <li>Would it be useful to relax the definition of odr for such cases like b in the future?</li>
  </ol>
  
  <p>Thank you in advance!</p>