This problem may be related to Bug report 17470. The typeinfo of a template class instantiation can not be changed with __attribute__ ((visibility("default"))). Example:
template<typename T> class Abc{ public: virtual ~Abc(){} }; template class __attribute__ ((visibility("default"))) Abc<int>; Abc<int> tmp; [EMAIL PROTECTED]/src/c++/test]1238: g++ -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -c visibility.cpp [EMAIL PROTECTED]/src/c++/test]1239: g++ -shared visibility.o -o libvisibility.so [EMAIL PROTECTED]/src/c++/test]1240: nm -C libvisibility.so | grep Abc 00000764 t Abc<int>::Abc() 0000072a t Abc<int>::~Abc() 000006f0 t Abc<int>::~Abc() 000006b6 t Abc<int>::~Abc() 00001930 d typeinfo for Abc<int> 000007ee r typeinfo name for Abc<int> 00001938 d vtable for Abc<int> Using pragma works: template<typename T> class Abc{ public: virtual ~Abc(){} }; #pragma GCC visibility push(default) template class Abc<int>; #pragma GCC visibility pop Abc<int> tmp; [EMAIL PROTECTED]/src/c++/test]1241: g++ -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -c visibility.cpp [EMAIL PROTECTED]/src/c++/test]1242: g++ -shared visibility.o -o libvisibility.so [EMAIL PROTECTED]/src/c++/test]1243: nm -C libvisibility.so | grep Abc 000007c4 t Abc<int>::Abc() 0000078a t Abc<int>::~Abc() 00000750 t Abc<int>::~Abc() 00000716 t Abc<int>::~Abc() 00001990 V typeinfo for Abc<int> 0000084e V typeinfo name for Abc<int> 00001998 V vtable for Abc<int> Because #pragma can not be used in a macro I would prefer to use the __attribute__ syntax. -- Summary: typeinfo visibility of template class instantiation can not be changed with attribute Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: christoph dot pesch at siemens dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21243