title: Template tricks with const char* as a non-type parameter
body: <p>I am very well aware that passing directly a <code>const char*</code> as a template non-type parameter is erroneous, since two identical string literals defined in two different translation units may have different addresses (although most of the time the compilers use the same address). There is a trick one may use, see code below:</p>
  <pre><code>#include &lt;iostream&gt;
  
  template&lt;const char* msg&gt;
  void display()
  {
      std::cout &lt;&lt; msg &lt;&lt; std::endl;
  }
  
  // need to have external linkage 
  // so that there are no multiple definitions
  extern const char str1[] = &quot;Test 1&quot;; // (1)
  
  // Why is constexpr enough? Does it have external linkage?
  constexpr char str2[] = &quot;Test 2&quot;;    // (2)
  
  // Why doesn't this work? 
  extern const char* str3 = &quot;Test 3&quot;;  // (3) doesn't work
  
  // using C_PTR_CHAR = const char* const;   // (4) doesn't work either
  extern constexpr C_PTR_CHAR str4 = &quot;Test 4&quot;; 
  
  int main()
  {
      display&lt;str1&gt;();    // (1')
      display&lt;str2&gt;();    // (2')
      // display&lt;str3&gt;(); // (3') doesn't compile 
      //display&lt;str4&gt;();  // (4') doesn't compile
  }
  </code></pre>
  <p>Basically in (1) we declare and <em>define</em> an array with external linkage, which can then be used as a template parameter in (1'). I understand this very well. However, I don't understand:</p>
  <ol>
  <li><p>Why does the <code>constexpr</code> version (2) work? Does <code>constexpr</code> have external linkage? If not, then defining the same string literal in a different translation unit may lead to duplicate template instantiation.</p>
  </li>
  <li><p>Why don't (3) and (4) work? It seems perfectly reasonable for me, but the compiler doesn't believe so:</p>
  <blockquote>
  <p>error: 'str3' is not a valid template argument because 'str3' is a variable, not the address of a variable</p>
  </blockquote>
  </li>
  </ol>