https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71154
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to James Abbatiello from comment #1)
> Created attachment 38502 [details]
> Too simple patch
This patch is wrong as you are modifying more than just about visibility
attribute.
> Trying to apply attributes (like visibility("default")) to an
> explicit template instantiation does not work if the type has
> been previously mentioned in the translation unit.
This is correct GCC behavior. Because it has to apply to the first time the
type is used.
Here is why:
I it applies after declaration, then some other types need to be changed too.
The ones which use that type.
For an example:
template <typename T>
class C
{
void foo();
};
class D
{
C<int> a;
};
template class __attribute__((visibility("hidden"))) C<int>;
---- CUT -----
If attributes applies at the end, then D gets hidden visibility and you need to
redo that type. So this is the reason why attributes can't apply after they
have been declared.