title: Why is it illegal to have multi-line constexpr functions?
body: <p>According to <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf" rel="nofollow noreferrer">Generalized Constant Expressions—Revision 5</a> the following is illegal:</p>
  <pre><code>constexpr int g(int n) // error: body not just ‘‘return expr’’
  {
      int r = n;
      while (--n &gt; 1) r *= n;
      return r;
  }
  </code></pre>
  <p>This is because all 'constexpr' functions are required to be of the form <code>{ return expression; }</code>. I can't see any reason that this needs to be so.</p>
  <p>In my mind, the only thing that would really be necessary is that no external state information is read/written and the parameters being passed in are also 'constexpr' statements. This would mean that any call to the function with the same parameters would return the same result, thus it is possible to &quot;know&quot; at compile time.</p>
  <p>My main problem with this is that it just seems to force you to do really roundabout forms of looping and hoping that the compiler optimises it so that its just as fast for non-constexpr calls.</p>
  <p>To write a valid <code>constexpr</code> for the above example you could do:</p>
  <pre><code>constexpr int g(int n) // error: body not just ‘‘return expr’’
  {
      return (n &lt;= 1) ? n : (n * g(n-1));
  }
  </code></pre>
  <p>But this is a lot harder to understand and you have to hope that the compiler takes care of the tail recursion when you call with parameters that violate the requirements for <code>const-expr</code>.</p>