[C++] Attributes and explicit template instantiations

Matt Austern austern@apple.com
Fri Nov 5 20:14:00 GMT 2004


The C++ parser allows the following:
   template __attribute__ ((visibility("hidden"))) void xyzzy<int>() ;
However, the visibility attribute is ignored.

As far as I can tell from looking at parser.c, this has nothing to do 
with visibility; it's just a quirk in attribute handling that nobody 
seems to have thought much about.  Possibly I'm missing something, but 
what it looks like to me is that cp_parser_explicit_instantiation 
accepts the __attribute__ list almost by accident, because it calls  
cp_parser_decl_specifier_seq, and the GNU compiler always considers an 
attribute to be a decl specifier, but that it doesn't ever do anything 
with any attributes it collects.

So we've got the same question as before: is the bug that we're 
throwing away the attributes instead of applying them to the template 
instantiation, or is the bug that we accept attributes here at all? 
Silently ignoring them is clearly wrong; we should either apply them or 
give a diagnostic.  I have a slight preference for the former, but I 
could live with either.

			--Matt



More information about the Gcc mailing list