title: What determines whether a constexpr function is a constant expression?
body: <p>(compiler used is gcc with c++17 as far as I know (difficult to find this in visual studio))</p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  void increment( int&amp; v )
  {
      ++v;
  }
  
  int constexpr f()
  {
      int v = 0;
      increment( v );
      return v;
  }
  
  int main( )
  {
      cout &lt;&lt; f( ) &lt;&lt; '\n';
  }
  </code></pre>
  <p>The above code gives the error on compile:</p>
  <blockquote>
  <p>constexpr function 'f' cannot result in a constant expression.</p>
  </blockquote>
  <p>As I understand it this is because the function <code>increment</code> is not a constexpr. What confuses me is that the following code compiles fine:</p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  void increment( int&amp; v )
  {
      ++v;
  }
  
  int constexpr f()
  {
      int v = 0;
      for( int i = 0; i &lt; 1; ++i )
      {
          increment( v );
      }   
      return v;
  }
  
  int main( )
  {
      cout &lt;&lt; f( ) &lt;&lt; '\n';
  }
  </code></pre>
  <p>This code is functionally the same and it does compile, even though increment is still not a constexpr. I don't understand how it's possible that a for-loop through the range [0, 1) causes the compiler to realize that the function <code>f</code> actually is a constexpr.</p>
  <p>If anyone can give some insights on constexpr in c++ and this apparent inconsistency, I'd greatly appreciate it.</p>