This is the mail archive of the gcc@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]

Re: Visibility and C++ Classes/Templates


On Wed, Jun 28, 2006 at 10:24:27PM -0400, Geoffrey Keating wrote:
> Suppose a library template has (my syntax may not be quite right):
> 
> template struct foo <class T> __attribute__((visibility("default"))) {
>   static T my_var;
>   T inc (T x) { return my_var += x; }
> };
> 
> The intention is that all foo<T>s share the same my_var.  Obviously  
> this won't work right if a #pragma on the instantiation overrides the  
> visibility.

Right, but it doesn't feel right to me to protect the user from himself.
In this case, the user might say "it hurts when I do that" and we can
reply "then don't do that!"

There might be another case where changing the visibility is exactly
what the user needs to do to solve a problem.

> Right; and I'm not saying that there should be no way to achieve  
> this, it's just that people are often unsure or unknowing of what  
> pragmas might be in effect, so it might be better if they had to  
> explicitly use an attribute.  Certainly if someone says
> 
> template <> foo<myclass> __attribute__((visibility("hidden")));
> 
> then they ought to get what they asked for.

Agreed.  We shouldn't try to outsmart the user; it makes sense to
use the most specific information we are given (so an attribute
on a specialization would override an attribute on the template).





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