title: Why are external-linkage variables usable as constant expressions?
body: <p>In a discussion on another question, I was given an example where apparently linkage of an identifier affected its usability in a constant expression:</p>
  
  <pre><code>extern char const a[] = "Alpha";
  char constexpr b[] = "Beta";
  char const g[] = "Gamma";
  
  template &lt;const char *&gt; void foo() {}
  
  auto main()
      -&gt; int
  {
      foo&lt;a&gt;();     // Compiles
      foo&lt;b&gt;();     // Compiles
      foo&lt;g&gt;();     // Doesn't compile
  }
  </code></pre>
  
  <p>The error from the last (with GCC) is:</p>
  
  <pre><code>test.cc: In function 'int main()':
  test.cc:12:13: error: the value of 'g' is not usable in a constant expression
           foo&lt;g&gt;();     // Doesn't compile
               ^
  test.cc:3:16: note: 'g' was not declared 'constexpr'
       char const g[] = "Gamma";
                  ^
  </code></pre>
  
  <p>I may have missed the significance of the example in the earlier discussion, because I believed that it could not have been just linkage which differentiated <code>foo&lt;a&gt;</code> from <code>foo&lt;g&gt;</code> - however, I have begun to doubt that position.</p>
  
  <ol>
  <li>Is it really the linkage, or is it some other attribute granted by <code>extern</code>, that allows <code>foo&lt;a&gt;()</code>?</li>
  <li>What is the rationale for allowing <code>foo&lt;a&gt;()</code> but not <code>foo&lt;g&gt;()</code>? In particular, if it is determined by linkage, why should internal linkage cause a variable not to be usable as a constant expression when the same variable declared <code>extern</code> <em>would</em> be usable?</li>
  <li>It was suggested that the question of the symbol being visible (or not) to the linker is relevant here. To me, it seems that the fact the <code>foo&lt;b&gt;</code> variant is still allowed even when <code>static</code> is added disproves this - or am I mistaken?</li>
  <li>(The difference between <code>foo&lt;b&gt;()</code> and <code>foo&lt;g&gt;()</code> is adequately covered by <a href="https://stackoverflow.com/questions/13346879/const-vs-constexpr-on-variables.">other questions</a>, I think).</li>
  </ol>