title: Recursive computation using variable templates - gcc vs clang
body: <p>Consider the following example:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  
  template &lt;int N&gt;
  int fib = fib&lt;N - 1&gt; + fib&lt;N - 2&gt;;
  
  template &lt;&gt; int fib&lt;2&gt; = 1;
  template &lt;&gt; int fib&lt;1&gt; = 1;
  
  int main()
  {
      std::printf("%d %d %d", fib&lt;4&gt;, fib&lt;5&gt;, fib&lt;6&gt;);
  }
  </code></pre>
  
  <ul>
  <li><p>GCC 7.x, 8.x, 9.x, and 10.x all print out the expected result of <code>3 5 8</code>.</p></li>
  <li><p>Clang 5.x, 6.x, 7.x, 8.x, 9.x, and 10.x all print out <code>1 3 4</code> as a result.</p></li>
  </ul>
  
  <p><a href="https://gcc.godbolt.org/z/3DXKeC" rel="noreferrer"><strong>live example on godbolt.org</strong></a></p>
  
  <hr>
  
  <p>Clang's behavior is surprising. </p>
  
  <p><strong>Is there any subtle interaction between variable template instantiation, global variables, and recursion in the C++ standard that I am missing?</strong></p>
  
  <p><strong>Or is this a long-standing Clang bug?</strong> </p>
  
  <p>By the way, marking <code>fib</code> as <code>constexpr</code> solves the issue (<a href="https://gcc.godbolt.org/z/_zH6Mm" rel="noreferrer"><strong>on godbolt.org</strong></a>).</p>