title: Can you legally dynamic_cast to non-polymorphic base class of a polymorphic class
body: <p>In <a href="https://stackoverflow.com/a/44329645/1277769">this answer</a>, the following scenario came up:</p>
  
  <pre><code>#include &lt;cassert&gt;
  
  struct A {};
  
  struct B { virtual ~B(){} };
  
  struct AA{};
  template &lt;class T&gt;
  struct C : A, T {};
  
  int main()
  {
    B * b = new C&lt;B&gt;;
    AA * aa = new C&lt;AA&gt;;
    assert(dynamic_cast&lt;A*&gt;(b));
    assert(dynamic_cast&lt;A*&gt;(aa)); //this line doesn't compile, as expected
  }
  </code></pre>
  
  <p>On g++ 4.8.4 (Ubuntu), this compiles and the assert passes.  My question is, is that really legal?  I feel like you shouldn't be able to <code>dynamic_cast</code> to a non-polymorphic class at all, but I freely admit that I'm not an expert in what's happening here.</p>
  
  <p>When I tried the opposite direction:</p>
  
  <pre><code>dynamic_cast&lt;B*&gt;((A*)(new C&lt;B&gt;));
  </code></pre>
  
  <p>it fails to compile, stating that "source type is not polymorphic".  I feel like that's a clue, but it still seems a stretch to find the non-polymorphic base class that belongs to a class that the current pointer is a base of (did that sentence make sense?).</p>