title: Possible to instantiate templates using a for loop in a C++14 constexpr function?
body: <p>I've been messing around with an SVN build of clang to experiment with the relaxed rules for <code>constexpr</code>. One of the things I've been unable to determine as of yet is whether it's possible to loop through the elements inside a tuple at compile-time in a constexpr function.</p>
  
  <p>Because I don't have a C++14 compliant standard library to test on, I've prepared the following equivalent test:</p>
  
  <pre><code>template&lt;int N&gt;
  constexpr int foo() {
    return N;
  }
  
  constexpr int getSum() {
    auto sum = 0;
    for (auto i = 0; i &lt; 10; ++i) {
      sum += foo&lt;i&gt;();
    }
    return sum;
  }
  
  constexpr auto sum = getSum();
  </code></pre>
  
  <p>The interesting part here is <code>foo&lt;i&gt;()</code>. In a non-constexpr function I would expect this to fail to compile, because you simply cannot use a runtime int to generate a compile-time instantiation of a template. Because this is a <code>constexpr</code> function, however, I question whether this would be possible. In particular, the value is known at compile-time, even if it is allowed to mutate.</p>
  
  <p>I know that the following code <em>will</em> compile:</p>
  
  <pre><code>constexpr auto nValue = 2;
  foo&lt;nValue&gt;();
  </code></pre>
  
  <p>In SVN clang, my first example does not:</p>
  
  <pre>
  test2.cpp:19:12: error: no matching function for call to 'foo'
      sum += foo();
             ^~~~~~
  test2.cpp:11:15: note: candidate template ignored: invalid explicitly-specified
        argument for template parameter 'N'
  constexpr int foo() {
                ^
  </pre>
  
  <p>For starters, I struggle to interpret the second part of this error message. That aside, is it mandated by the C++14 standard, and if so, does anyone know why this syntax wouldn't be allowed (simple oversight or to protect against something)?</p>