title: How does a compiler treat lambdas differently than regular functions?
body: <p>I wonder how a compiler treats lambda functions as opposed to regular functions. Even excluding the capture-list, as I think it's called, it seems to behave slightly differently.</p>
  
  <p>For example, as used in my last post, <a href="https://stackoverflow.com/questions/54353463/trying-to-pass-a-constexpr-lambda-and-use-it-to-explicitly-specify-returning-typ">Trying to pass a constexpr lambda and use it to explicitly specify returning type</a>, I used a constexpr lambda and passed it as a regular function parameter. I quote a part of the answer.</p>
  
  <blockquote>
    <p>Parameters to constexpr functions are not themselves constexpr objects - so you cannot use them in constant expressions.</p>
  </blockquote>
  
  <pre><code>template &lt;typename Lambda_T&gt;
  constexpr static auto foo(Lambda_T l) {
      return std::array&lt;event, (l())&gt;{};
  } 
  // Compiles with GCC (C++17), though ill-formed (according to the answer of my last post)
  </code></pre>
  
  <p>Though, what catches my eye is that this does compile passing a <code>constexpr lambda</code>, but does not compile passing a constexpr regular (global) function. What causes this difference? 
  And are there other differences of behaviour of the compiler between regular functions and lambda-functions?</p>
  
  <p><strong>Edit: Example of Lambda-implementation</strong></p>
  
  <pre><code>foo([](){ return 4; }); // C++17 Lambda's are implicitly constexpr
  </code></pre>
  
  <p>The lambda is basically a wrapper for the value in this case.</p>
  
  <p><strong>Edit: Global function</strong></p>
  
  <p>Whenever a global function is passed, the compiler will complain - as opposed to using a lambda - that this function, regardless of whether it is defined constexpr or not, cannot be used in a constant condition:</p>
  
  <pre><code>prog.cc:8:20: error: 'l' is not a constant expression
  </code></pre>