[Bug c++/81764] [6/7/8 Regression] Visibility attributes for explicitly instantiated template class get warned if it has been implicitly instantiated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81764 --- Comment #3 from Martin Sebor --- 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 class g; template 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<>; ^~~
[Bug c++/81764] [6/7/8 Regression] Visibility attributes for explicitly instantiated template class get warned if it has been implicitly instantiated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81764 Jason Merrill changed: What|Removed |Added Status|NEW |RESOLVED CC||jason at gcc dot gnu.org Resolution|--- |INVALID --- Comment #2 from Jason Merrill --- Yes, this behavior is intended; just like you can't explicitly specialize a class after it's been instantiated, you can't specify attributes either. The C++ standard is even stricter, saying "No attribute-specifier-seq shall appertain to an explicit instantiation."
[Bug c++/81764] [6/7/8 Regression] Visibility attributes for explicitly instantiated template class get warned if it has been implicitly instantiated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81764 Richard Biener changed: What|Removed |Added Priority|P3 |P2
[Bug c++/81764] [6/7/8 Regression] Visibility attributes for explicitly instantiated template class get warned if it has been implicitly instantiated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81764 Richard Biener changed: What|Removed |Added Target Milestone|--- |6.5
[Bug c++/81764] [6/7/8 Regression] Visibility attributes for explicitly instantiated template class get warned if it has been implicitly instantiated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81764 Martin Sebor changed: What|Removed |Added Status|UNCONFIRMED |NEW Known to work||4.1.0 Keywords||diagnostic Last reconfirmed||2018-02-15 CC||msebor at gcc dot gnu.org See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=84318 Ever confirmed|0 |1 Summary|Visibility attributes for |[6/7/8 Regression] |explicitly instantiated |Visibility attributes for |template class get warned |explicitly instantiated |if it has been implicitly |template class get warned |instantiated|if it has been implicitly ||instantiated Known to fail||4.2.2, 4.3.2, 4.6.0, 5.4.0, ||6.3.0, 7.2.0, 8.0 --- Comment #1 from Martin Sebor --- The warning might be helpful if the explicit specialization declaration attempted to specify different visibility that the primary template (assuming the declaration of the specialization inherits the attribute from the template) but it's pointless when it simply reiterates the same visibility, and it would be wrong if the specialization didn't "inherit" its attributes from the primary. With that, I would say that it's not desirable (even though it is intended in other cases). With that I confirm it as a bug. The warning wasn't issued prior to r115086 (committed into GCC 4.2) so it's also aa regression, albeit a very old one. As the test case below shows, the warning isn't unique to the visibility attribute. It affects other type attributes as well. Here too the warning is pointless regardless of how attributes are treated. Unfortunately, specifying an attribute on the declaration of an explicit instantiation isn't specified either in C++ or in G++ and it not clear that we know or have consensus what we want it to mean (see for example bug 84318), so this bug isn't likely to get a lot attention until the confusion around attributes and templates has been cleared up. $ cat t.C && gcc -S -Wall -Wextra -Wpedantic t.C template class A; template struct alignas (32) A { static int f () { return A<>::f (); } }; extern template struct alignas (32) A<>; static_assert (alignof (A<>) == 32, ""); t.C:9:37: warning: type attributes ignored after type is already defined [-Wattributes] extern template struct alignas (32) A<>; ^~~