title: GCC and Clang disagree about C++17 constexpr lambda captures
body: <p>Consider this example which declares a variable as constexpr, captures it by copy in a lambda, and declares another constexpr variable which is the result of a constexpr function unwrapping a non-type template parameter from the original variable.</p>
  
  <pre><code>#include &lt;utility&gt;
  
  template&lt;int I&gt;
  constexpr auto unwrap(std::integral_constant&lt;int, I&gt;) {
    return I;
  }
  
  int main() {
    constexpr auto i = std::integral_constant&lt;int, 42&gt;{};
    constexpr auto l = [i]() {
      constexpr int x = unwrap(i);
    };
  }
  </code></pre>
  
  <p>Clang (trunk) accepts this code. (<a href="https://wandbox.org/permlink/2H7zezNFXdQdyaBz" rel="noreferrer">wandbox</a>)</p>
  
  <p>GCC (trunk) fails with the following error message (<a href="https://wandbox.org/permlink/oB7VEymVTfDQuxYG" rel="noreferrer">wandbox</a>):</p>
  
  <pre><code>lambda_capture.cpp:11:31: error: the value of ‘i’ is not usable in a constant expression
       constexpr int x = unwrap(i);
                                 ^
  lambda_capture.cpp:10:28: note: ‘i’ was not declared ‘constexpr’
     constexpr auto l = [i]() {
  </code></pre>
  
  <p>Which compiler is correct? It seems to me that this is a GCC bug, where the constexpr-ness of lambda captures is not correctly propagated to the lambda context.</p>