title: Does undefined behavior affect static_assert?
body: <p>Consider the following code:</p>
  
  <pre><code>SomeType x=getX();
  for(auto mask = 1u&lt;&lt;(CHAR_BIT*sizeof x - 1);/*...*/;/*...*/)
  {
      static_assert(sizeof mask&gt;=sizeof x, "Type of numeric parameter is too long");
      /*...*/
  }
  </code></pre>
  
  <p>Here, <code>mask</code> will have type <code>unsigned</code>. Suppose <code>SomeType</code> is <code>long long</code>. Then the initialization of <code>mask</code> will have undefined behavior due to shifting by too much. But OTOH, there's a <code>static_assert</code>, which checks that undefined behavior can't happen at runtime (because the code would fail to compile).</p>
  
  <p>But since UB can lead to time paradoxes and other surprises, I'm not so sure that <code>static_assert</code> is guaranteed to actually work in this case. Is there any reason to be sure of this? Or should this code be redone to make <code>static_assert</code> appear before initialization of <code>mask</code>?</p>