Hi, I'm currently experimenting with the -fvisibility=hidden visibility flag. During that I have stumbled upon some very peculiar behavior of GCC, which I managed to boil down to the following small example: template < typename _T > class TemplatedClass { public: TemplatedClass (); }; template < typename _T > class DependentTemplatedClass { public: DependentTemplatedClass (); _T m_Member; }; These classes are explicitly instantiated in a library. In one compilation unit I do: template class LIBRARY_EXPORT TemplatedClass < int >; And in another: template class LIBRARY_EXPORT DependentTemplatedClass < TemplatedClass < int > >; The LIBRARY_EXPORT macro sets the visibility of the instantiation to default (i.e. public). When I compile the library like this (see the BuildFail.sh script in the attachment). The TemplatedClass<int>::TemplatedClass symbol appears twice in the library, the first being hidden the second being a weak symbol. When linking to this library the linker cannot find this symbol. However when I export the class definition (as well as the instantiation), the linking goes fine (see BuildWorkaround.sh). In this case the symbol is defined twice in the library, both times as a weak symbol. The cause seems to be the instantiation of DependentTemplatedClass<TemplatedClass<int > >, which induces an instantiation of TemplatedClass<int> as well. However I would expect this instantiation to have public visibility as well, because the DependentTemplatedClass instantiation is public. Is this a GCC bug, or am I doing something wrong here? best, Jeroen
Attachment:
GccVisibility.tar.bz2
Description: BZip2 compressed data