title: Are there cases where downcasting an actual Base to a Derived would be defined?
body: <p>In the general case, it is (a very well deserved) Undefined Behavior to dowcast from a (dynamic) <code>Base</code> to one of the deriving classes <code>Derived</code></p>
  
  <h2>The obvious UB</h2>
  
  <pre><code>class Base
  {
  public:
      virtual void foo()
      { /* does something */ }
  
      int a;
  }
  
  class Derived : public Base
  {
  public:
      virtual void foo()
      { /* does something different */ }
  
      double b;
  }
  
  Base obj;
  Derived derObj = *static_cast&lt;Derived *&gt;(&amp;obj);  // &lt;- here come the demons
  </code></pre>
  
  <p>In the current implementation approach of compilers, here there would obviously be at least the problems of inconsistent values in the Vtable and b containing garbage values. So it makes sense the standard does not define the behavior of a downcast in those conditions.</p>
  
  <h2>The not so obvious naive case</h2>
  
  <p>Yet I was curious to know <strong>if there were some concessions to this rule in specific cases ?</strong>
  For an example :</p>
  
  <pre><code>class Base
  {
  public:
      void foo()
      { /* does something */ }
  
      int a = 1;
      double b = 2.;
  }
  
  class DerivedForInt : public Base
  {
      int getVal()
      { return a }
  }
  
  Base obj;
  DerivedForInt derObj = *static_cast&lt;DerivedForInt *&gt;(&amp;obj);  // &lt;- still an UB ?
  </code></pre>
  
  <p>Here we can easily imagine compiler doing the right thing. <strong>But from the standard perspective, is it still undefined ?</strong></p>
  
  <p>Edit : <strong>static_cast</strong> is a random choice for illustration purpose, it is also interesting if working with other casts !</p>