title: g++ and clang++ different behaviour with lambda capturing `std::integral_constant` by reference
body: <p>Given the following code </p>
  
  <pre><code>#include &lt;type_traits&gt;
  
  int main ()
   {
     std::integral_constant&lt;int, 42&gt; ic;
  
     [&amp;]{ constexpr int i = ic; (void)i; }();
   }
  </code></pre>
  
  <p>(the <code>(void)i;</code> is just to avoid a "unused variable" warning) clang++ compile without problem where g++ gives the following error</p>
  
  <pre><code>prog.cc: In lambda function:
  prog.cc:7:27: error: '__closure' is not a constant expression
      7 |    [&amp;]{ constexpr int i = ic; (void)i; }();
        |                           ^~
  </code></pre>
  
  <p>Capturing by value</p>
  
  <pre><code>[=]{ constexpr int i = ic; (void)i; }();
  </code></pre>
  
  <p>both compilers compile without problem.</p>
  
  <p>The question, as usual, is: who's right? g++ or clang++?</p>
  
  <p><strong>-- EDIT --</strong></p>
  
  <p>As pointed by JVApen, <code>ic</code> isn't defined <code>constexpr</code>; so how can a not-constexpr variable initialize a <code>constexpr</code> variable?</p>
  
  <p>Anyway, the behavior doesn't change defining <code>ic</code> as <code>constexpr</code></p>
  
  <pre><code>constexpr std::integral_constant&lt;int, 42&gt; ic;
  </code></pre>
  
  <p>clang++ compile without problem; g++ gives an error capturing by reference.</p>
  
  <p><strong>-- EDIT --</strong></p>
  
  <p>As pointed by Jans, defining <code>ic</code> as <code>constexpr</code> and using aggregate initialization</p>
  
  <pre><code>constexpr std::integral_constant&lt;int, 42&gt; ic{};
  </code></pre>
  
  <p>both compilers compile without problem.</p>
  
  <p>But without <code>constexpr</code></p>
  
  <pre><code>std::integral_constant&lt;int, 42&gt; ic{};
  </code></pre>
  
  <p>g++ gives the usual error.</p>