This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Visibility and C++ Classes/Templates
- From: Ian Lance Taylor <iant at google dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: Jason Merrill <jason at redhat dot com>, gcc at gcc dot gnu dot org
- Date: 23 Jun 2006 15:28:27 -0700
- Subject: Re: Visibility and C++ Classes/Templates
- References: <449C469E.9000201@redhat.com> <449C6187.4070406@codesourcery.com>
Mark Mitchell <mark@codesourcery.com> writes:
> Jason Merrill wrote:
> > Now, templates:
> >
> > template<class T> __attribute((visibility ("hidden")) T f(T);
> > #pragma GCC visibility push(default)
> > extern template int f(int);
> > #pragma GCC visibility pop
> >
> > This could really go either way. It could be considered similar to the
> > above case in that f<int> is in a way "part" of f<T>, but there isn't
> > the same scoping relationship. Also, there isn't the
> > declaration/definition problem, as the extern template directive is the
> > first declaration of the instantiation. In this case I am inclined to
> > respect the #pragma rather than the attribute on the template.
>
> I'd tend to say that the attribute wins, and that if you want to specify
> the visibility on the template instantiation, you must use the attribute
> on the instantiation, as you suggest:
Don't you still have to deal with this case?
#pragma GCC visibility push(hidden)
template<class T> T f(T);
#pragma GCC visibility pop
...
#pragma GCC visibility push(default)
extern template int f(int);
#pragma GCC visibility pop
Personally I wouldn't mind saying that the attribute always beats the
pragma, but it seems to me that there is still the potential for
ambiguity.
Ian