title: Cannot make std::array a constexpr in C++
body: <p>I am getting 'error C3615: constexpr function 'to_array' cannot result in a constant expression' compiler error with VS2017 in the code below:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;array&gt;
  
  template &lt;typename T&gt;
  static constexpr std::array&lt;std::uint8_t, sizeof(T)&gt; to_array(T value)
  {
      std::array&lt;std::uint8_t, sizeof(T)&gt; result {};
  
      for (std::size_t i{ sizeof(T) }; i != 0 ; --i)
      {
          result[i - 1] = static_cast&lt;uint8_t&gt;(value &gt;&gt; ((sizeof(T) - i) * 8));
      }
  
      return result;
  }
  
  int main()
  {
      constexpr uint64_t sample = UINT64_C(0xab28ecb46814fe75);
  
      //error C3615: constexpr function 'to_array' cannot result in a constant expression
      constexpr auto a = to_array(sample);
  
      return 0;
  }
  </code></pre>
  
  <p>If theoretically <a href="https://stackoverflow.com/questions/14267399/can-stdarray-be-used-in-a-constexpr-class">std::array can be constexpr</a>, why am I getting the error here?</p>
  
  <p>EDIT1:</p>
  
  <p>it compiles without the loop:</p>
  
  <pre><code>template &lt;typename T&gt;
  static constexpr std::array&lt;std::uint8_t, sizeof(T)&gt; to_array(T value)
  {
      std::array&lt;std::uint8_t, sizeof(T)&gt; result {};
  
      //this is OK
      return result;
  }
  </code></pre>
  
  <p>EDIT2:</p>
  
  <p>the full error message with the loop is:</p>
  
  <pre><code>error C3615: constexpr function 'to_array' cannot result in a constant expression
  note: failure was caused by an uninitialized variable declaration
  note: see usage of 'result'
  </code></pre>