title: Incorrect cast - is it the cast or the use which is undefined behavior
body: <p>If I do a cast from a Base to a Derived type, but the Base type isn't an instance of derived type, but only use the result if it is, do I get undefined behaviour?</p>
  
  <p>Hard to understand what I'm asking? take a look at this example:</p>
  
  <pre><code>struct Animal { int GetType(){...} };
  struct Dog : Animal { bool HasLoudBark(){...}};
  struct Cat : Animal { bool HasEvilStare(){...} };
  
  Animal * a = ...;
  Dog* d = static_cast&lt;Dog*&gt;(a);
  
  if(a-&gt;GetType() == DogType &amp;&amp; d-&gt;HasLoudBark())
      ....
  </code></pre>
  
  <p>In this case <code>a</code> may or not be a <code>Dog</code>. We always do the <code>static_cast</code> of <code>a</code> to <code>Dog * d</code> but we never use <code>d</code> unless we're sure its a <code>Dog</code>.</p>
  
  <p>Assuming that <code>a</code> is not a <code>Dog</code>, is this undefined behaviour at the point of the cast? Or is it defined as we don't actually use <code>d</code> unless it is really is a <code>Dog</code>?</p>
  
  <p>References to the relevant parts of the standard are appreciated.</p>
  
  <p>(Yes I know I can use dynamic_cast, and RTTI, and probably this isn't great code, but I'm more interested in whether this is valid)</p>