Allow attributes on template explicit instantiations

40 views
Skip to first unread message

Matthew Woehlke

unread,
Aug 24, 2016, 1:37:52 PM8/24/16
to std-pr...@isocpp.org
Consider the following code which exports an explicit instantiation of a
template (e.g. imagine this is in a .cpp file of a library):

template <typename T> T foo(T*)
{
// ...
}
template FOO_EXPORT int foo<int>(int*);

Modern C++ allows FOO_EXPORT on ELF platforms using GCC and Clang to be
defined as `[[gnu::visibility("default")]]`... right?

Alas, no. Attributes on explicit instantiations are explicitly forbidden
([dcl.attr.grammar]/5). (Despite that, GCC is happy to DTRT here. Clang,
however, enforces the standard, even though this particular prohibition
- especially for the attribute in this example - seems to be of
questionable value.)

This is obviously unfortunate. Is there any reason for this restriction
to be in place? If not, I propose to remove it.

--
Matthew

Matthew Woehlke

unread,
Aug 26, 2016, 10:32:05 AM8/26/16
to std-pr...@isocpp.org
That exciting, huh?

Well, here's a paper. Comments appreciated!

--
Matthew
dxxxx-instantiation-attributes.html
dxxxx-instantiation-attributes.rst
Reply all
Reply to author
Forward
0 new messages