This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

&typeid(T) != &typeid( T() ) [was dynamic_cast in python module]


Searching a bit on the problem reported in 'dynamic_cast in python module', I found out that in some dynamic library following two lines (which are directly one after the other and thus in the same dynamic library) print two different addresses:

1) std::cout<<&typeid(T)<<":"<<typeid(T).name()<<'\n';
2) T t ; std::cout<<&typeid(t)<<":"<<typeid(t).name()<<'\n';

(Where T is a template class derived from some non-template base-class)

So the address of the type_info objects in line 1 and 2 are different, the names however are identical. I have searched a lot in the archives but have never seen a problem like this being reported (all problems reported are accross dynamic library boundaries)

The above problem occurs in a python extension module. So I wanted to regenerate the problem in a small test-case but only succeeded partially. In following small test-case I got a surprising (to me) result too:

<test>
#include <iostream>

class A {
public:
virtual ~A() {}
} ;

template < class T > class B {} ;

void main()
{
  typedef B<int> Bint ;
  std::cout<<&typeid(Bint)<<":"<<typeid(Bint).name()<<'\n';
  std::cout<<&typeid(Bint())<<":"<<typeid(Bint()).name()<<'\n';
  Bint bint ;
  std::cout<<&typeid(bint)<<":"<<typeid(bint).name()<<'\n';
} ;
</test>

the first and third cout print the same address and name, the second however prints another address and a name that can't even be demangled by c++filt ?!

Any ideas on how to investigate further the first problem and the reason for the second 'surprising result' would be greatly appreciated.

I'm using gcc 3.2 and ld 2.13.90.0.2 (RH8.0) for this test


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]