https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109503
Bug ID: 109503 Summary: attribute visibility on template specialization Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mpolacek at gcc dot gnu.org Target Milestone: --- (I know there are many bugs in this area but I'm not finding an exact dup of this very problem.) template<typename T>__attribute__((visibility("default"))) void foo() {} template<> __attribute__((visibility("protected"))) void foo<int>(); template<> __attribute__((visibility("protected"))) void foo<int>() {} $ ./cc1plus -quiet t.C t.C:3:58: warning: ‘void foo() [with T = int]’: visibility attribute ignored because it conflicts with previous declaration [-Wattributes] 3 | template<> __attribute__((visibility("protected"))) void foo<int>() {} | ^~~~~~~~ t.C:2:58: note: previous declaration of ‘void foo() [with T = int]’ 2 | template<> __attribute__((visibility("protected"))) void foo<int>(); | ^~~~~~~~ Should the foo<int> attribute override the primary template's attribute? In any case, at least the diagnostic is wrong.