title: Antlr cpp runtime Any bad cast of pointer?
body: <p>I get following error using antlr cpp runtime. 
  pseudo-code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;antlr4-common.h&gt;
  
  #include &lt;antlr4-runtime.h&gt;
  
  using namespace antlrcpp;
  using namespace antlr4;
  using namespace std;
  
  class B{
  public:
      virtual void myhello() = 0;
  };
  
  class A:public B{
  public:
      string name;
      A (string a):name(a){
      }
  
      virtual void myhello(){
          cout &lt;&lt; "hello "&lt;&lt; name &lt;&lt;endl;
      }
  };
  
  Any f1(){
    A *a = new A("hello");
    return Any(a);
  }
  
  Any f2(){
    B* v= f1().as&lt;B*&gt;();
    return Any(v);
  }
  
  
  int main(){
      auto x = f2();
      x.as&lt;A*&gt;()-&gt;myhello();
      return 0;
  }
  </code></pre>
  
  <p>Error: bad_cast of line <code>B* v= f1().as&lt;B*&gt;()</code>;</p>
  
  <p>However when I wrote <code>B* b= new A();</code> in <code>f1</code>, it becomes OK.</p>
  
  <p>I guess it is related to <em>covariance</em>.</p>
  
  <p>an <code>A*</code> instance can always be casted to <code>B*</code> since <code>B</code> is the base of <code>A</code>.</p>
  
  <p>However <code>Any&lt;A*&gt;</code> in antlr-runtime cannot be <code>as &lt;B*&gt;()</code>.</p>