Bug 21243 - typeinfo visibility of template class instantiation can not be changed with attribute
Summary: typeinfo visibility of template class instantiation can not be changed with a...
Status: RESOLVED DUPLICATE of bug 17470
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords: visibility
Depends on: 17470
Blocks:
  Show dependency treegraph
 
Reported: 2005-04-27 06:26 UTC by Christoph Pesch
Modified: 2006-06-23 01:11 UTC (History)
9 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2006-03-21 04:03:43


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Pesch 2005-04-27 06:26:16 UTC
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;

pesch@kstbu027[~/src/c++/test]1238: g++ -fPIC -fvisibility=hidden
-fvisibility-inlines-hidden -c visibility.cpp
pesch@kstbu027[~/src/c++/test]1239: g++ -shared visibility.o -o libvisibility.so
pesch@kstbu027[~/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;

pesch@kstbu027[~/src/c++/test]1241: g++ -fPIC -fvisibility=hidden
-fvisibility-inlines-hidden -c visibility.cpp
pesch@kstbu027[~/src/c++/test]1242: g++ -shared visibility.o -o libvisibility.so
pesch@kstbu027[~/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.
Comment 1 Andrew Pinski 2005-12-28 19:37:16 UTC
Confirmed.
Comment 2 Jason Merrill 2006-03-21 04:03:43 UTC
Probably the same bug as 17470.
Comment 3 Geoff Keating 2006-04-19 19:15:14 UTC
I think that the actual reported behaviour is not a bug.  Some related behaviour is covered by bug 26612, but in this particular case the name 'Abc' refers to something that is hidden, and so it shouldn't be possible to make an instantiation of Abc be not-hidden.

Probably trying to use a visibility attribute like this should not be allowed.
Comment 4 Jason Merrill 2006-06-23 01:11:39 UTC

*** This bug has been marked as a duplicate of 17470 ***