title: Why constexpr is not evaluated at compile time (MSVC 2015)?
body: <p>recently I've tried to take advantage of C++0x constexpr under MSVC 2015 and my objective was to achieve compile-time hash strings. I wrote a simple FNV-1a hash algorithm as a constexpr function using, as required, a single return statement (ternary operator) and calling only constexpr functions, here it is:</p>
  
  <pre><code>template &lt;size_t N&gt;
  constexpr U32 StringID_FNV1a_32(const char(&amp;str)[N], I32 charIndex = 0, U32 hash = 2166136261U)
  {
      return charIndex &lt; N-1 ? StringID_FNV1a_32(str, charIndex +1, (hash ^ str[charIndex]) * 16777619U) : hash;
  }
  </code></pre>
  
  <p>I also made a little macro to be able to change the algorithm under the hood without any trouble: </p>
  
  <pre><code>#define STRING_ID(str)  core::utility::StringID_FNV1a_32(str)
  </code></pre>
  
  <p>then I used this macro in my code, carefully checking if any breakpoint was hit and, also, the generated assembly code. Here's the little scenario:</p>
  
  <pre><code>//1. normal variable test
  U32 hash1 = STRING_ID("abc");  
  
  //2. enum test
  enum {    
      hash2 = STRING_ID("abc")
  };
  
  //3. constexpr variable test
  constexpr U32 hash3 = STRING_ID("abc");
  </code></pre>
  
  <p>And here the facts:</p>
  
  <ol>
  <li>first test was called at <strong>run time</strong></li>
  <li>second test was performed at compile time</li>
  <li>third test was called at <strong>run time</strong></li>
  </ol>
  
  <p>As you can imagine I'm a little confused about the first and the third attempt. </p>
  
  <p>Why in the third scenario is the compiler allowed to call the function at runtime? even though the msdn says clearly <em>"The primary difference between const and constexpr variables is that the initialization of a const variable can be deferred until run time whereas a constexpr variable must be initialized at compile time."</em> [<a href="https://msdn.microsoft.com/it-it/library/dn956974.aspx#Anchor_3]" rel="nofollow">https://msdn.microsoft.com/it-it/library/dn956974.aspx#Anchor_3]</a></p>
  
  <p>Can be related to the fact that I'm in debug mode with all the optimizations turned off? and what about the first test?, is there any way to force the compiler to perform the hash at compile time?</p>