title: Clang compile error related to static_assert and boost::hana
body: <p>Consider the following problem which compiles successfully on Clang 3.8 using <code>-std=c++14</code>.</p>
  
  <pre><code>#include &lt;boost/hana.hpp&gt;
  
  namespace hana = boost::hana;
  
  int main() {
      constexpr auto indices = hana::range&lt;unsigned, 0, 3&gt;();
      hana::for_each(indices, [&amp;](auto i) {
          hana::for_each(indices, [&amp;](auto j) {
              constexpr bool test = (i == (j == i ? j : i));
              static_assert(test, "error");
          });
      });
  }
  </code></pre>
  
  <p>The test is quite non-sensical but that is not the point. Consider now an alternative version where the test is directly put inside the <code>static_assert</code>:</p>
  
  <pre><code>#include &lt;boost/hana.hpp&gt;
  
  namespace hana = boost::hana;
  
  int main() {
      constexpr auto indices = hana::range&lt;unsigned, 0, 3&gt;();
      hana::for_each(indices, [&amp;](auto i) {
          hana::for_each(indices, [&amp;](auto j) {
              static_assert((i == (j == i ? j : i)), "error");
          });
      });
  }
  </code></pre>
  
  <p>Now I get a bunch of compile errors, saying</p>
  
  <blockquote>
    <p>error: reference to local variable <code>i</code> declared in enclosing lambda expression</p>
  </blockquote>
  
  <p><strong>Question: What causes the second version to fail?</strong></p>
  
  <p><em>Edit: Could this be a compiler bug? I turns out that when accessing <code>i</code> before the <code>static_assert</code>, everything compiles again:</em></p>
  
  <pre><code>#include &lt;boost/hana.hpp&gt;
  
  namespace hana = boost::hana;
  
  int main() {
      constexpr auto indices = hana::range&lt;unsigned, 0, 3&gt;();
      hana::for_each(indices, [&amp;](auto i) {
          hana::for_each(indices, [&amp;](auto j) {
              constexpr auto a = i;
              static_assert((i == (j == i ? j : i)), "error");
          });
      });
  }
  </code></pre>
  
  <p><em>Update: The same behaviour can be reproduced on Clang 4.0 and the current development branch 5.0.</em></p>
  
  <p><em>Update 2: As suggested by @LouisDionne, I filed this as a bug: <a href="https://bugs.llvm.org/show_bug.cgi?id=33318" rel="nofollow noreferrer">https://bugs.llvm.org/show_bug.cgi?id=33318</a>.</em></p>