title: Why is this cross-cast not allowed?
body: <p>Consider this simple example:</p>
  
  <pre><code>struct Base1 {};
  
  struct Base2 {};
  
  struct Derived : public Base1, public Base2 {};
  
  int main()
  {
     Derived foo;
     Base1* foo1 = &amp;foo;
     Base2* foo2 =  static_cast&lt;Base2*&gt;(foo1); 
  }
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Error: static_cast from 'Base1 *' to 'Base2 *', which are not related by inheritance, is not allowed
  </code></pre>
  
  <p>The compiler should have enough information to figure out that <code>Base2</code> can be reached from <code>Derived</code>  without RTTI (<code>dynamic_cast</code>) and having me to do:</p>
  
  <pre><code>Derived* foo3 = static_cast&lt;Derived*&gt;(foo1);
  Base2* foo2 = foo3;
  </code></pre>
  
  <p>Why isn't this allowed? (One could argue that the compiler doesn't know if <code>foo1</code> is of <code>Derived</code> type, but <code>static_cast</code> doesn't check the type anyway even when converting from <code>Base1</code> to <code>Derived</code> for example)</p>
  
  <p><em>Note: This <a href="https://stackoverflow.com/questions/44810204/cross-cast-attempt-using-static-cast-failing-why">question</a> is similiar to mine, but it's not quite the same because here we are cross-casting base classes, not derived ones</em></p>