This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Visibility and C++ Classes/Templates
Jason Merrill <jason@redhat.com> writes:
> Gabriel Dos Reis wrote:
> > Mark Mitchell <mark@codesourcery.com> writes:
> > | I'm just not comfortable with the idea of #pragmas affecting
> > | instantiations. (I'm OK with them affecting specializations, though; in
> > | that case, the original template has basically no impact, so I think
> > | it's fine to treat the specialization case as if it were any other
> > | function.)
> > I'm undecided whether #pragmas should not affect explicit
> > instantiations. They really are not like implicit instantiations
> > (which, I agree with you, should not be affected). Explicit
> > instantiations behave more like real declarations than implicit
> > instantiations.
>
> Yep. I'm sympathetic to Mark's position, but still tend to believe
> that the #pragma should affect explicit instantiations. Explicit
> instantiations are a way to make template instantiations conform more
> to the traditional declaration/definition model. We ignore the
> #pragmas for implicit instantiations because the user doesn't control
> the point of instantiation; with explicit instantiations, they do.
>
> Explicit instantiations don't behave just like implicit
> instantiations; there are other differences.
A consequence of this is that if a user instantiates a template that
they don't 'own' (that is, a template from a different module), they
must make sure that no #pragma is in effect, because the other module
may have a specific idea about what visibility should be used.
I'm not sure how exactly they can do this. Is there a visibility
pragma for "no setting"?
It seems like this would be a common enough mistake that there should
be a way to get a warning about it.
In the traditional declaration/definition model, if you try to change
the linkage of something you get an error...