[Bug c++/81764] [6/7/8 Regression] Visibility attributes for explicitly instantiated template class get warned if it has been implicitly instantiated
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Apr 6 18:08:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81764
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
This is another one of those cases where implementations diverge:
Clang and ICC silently accept the program in comment #0 and give an error for
the one in comment #1.
GCC issues -Wattributes for both.
MSVC silently accepts the program in comment #1 but gives a warning when the
alignment specified on the specialization is different than on the primary.
MSVC doesn't understand visibility attributes but it does accept __declspec
dllexport and dllimport. It allows the example in comment #0 with __declspec
(dllimport) and also with the primary declared dllexport and the instantiation
declared dllimport. That makes sense because both declarations would typically
appear this way in a library header and an explicit instantiation directive
declared dllexport in some source file of the library. The C++ constraint that
"no attribute-specifier-seq shall appertain to an explicit instantiation"
disallows this use case (one of the main uses cases in Windows class template
DLLs).
GCC for i686-pc-cygwin also issues a warning for this modified test case and so
is incompatible with MSVC:
$ cat pr81764.C && i686-pc-cygwin-g++ -S -Wall pr81764.C
template<typename ...> class g;
template<typename ...T>
class __declspec (dllexport) g
{
g() = default;
static int f(int x)
{
return g<>::yyy::u(x); // g<> instantiated here
}
struct yyy
{
static int u(int x){
return x+ sizeof...(T);
}
};
};
extern template class __declspec (dllimport) g<>;
template class g<>;
pr81764.C:22:46: warning: type attributes ignored after type is already defined
[-Wattributes]
extern template class __declspec (dllimport) g<>;
^~~
More information about the Gcc-bugs
mailing list