This is my first time attempting a contribution here so please point out any mistakes. I've tested this on x86_64-pc-linux-gnu in a VM.
-- James Abbatiello gcc/ChangeLog: PR c++/77306 * attribs.c (decl_attributes): Allow visibility attributes on explicit template instantiations. * gcc-family/c-attribs.c (handle_visibility_attribute): Likewise. --- gcc/attribs.c | 3 ++- gcc/c-family/c-attribs.c | 6 ------ gcc/testsuite/g++.dg/ext/visibility/warn4.C | 5 +++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/gcc/attribs.c b/gcc/attribs.c index 55b21271b39..ed1cfa1765b 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -534,7 +534,8 @@ decl_attributes (tree *node, tree attributes, int flags) if (TYPE_P (*anode) && (flags & (int) ATTR_FLAG_TYPE_IN_PLACE) - && TYPE_SIZE (*anode) != NULL_TREE) + && TYPE_SIZE (*anode) != NULL_TREE + && !is_attribute_p ("visibility", name)) { warning (OPT_Wattributes, "type attributes ignored after type is already defined"); continue; diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index f2a88e147ba..e3fb82aef21 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -1895,12 +1895,6 @@ handle_visibility_attribute (tree *node, tree name, tree args, name); return NULL_TREE; } - else if (TYPE_FIELDS (*node)) - { - error ("%qE attribute ignored because %qT is already defined", - name, *node); - return NULL_TREE; - } } else if (decl_function_context (decl) != 0 || !TREE_PUBLIC (decl)) { diff --git a/gcc/testsuite/g++.dg/ext/visibility/warn4.C b/gcc/testsuite/g++.dg/ext/visibility/warn4.C index 33e6f678592..a55f9682a12 100644 --- a/gcc/testsuite/g++.dg/ext/visibility/warn4.C +++ b/gcc/testsuite/g++.dg/ext/visibility/warn4.C @@ -1,10 +1,11 @@ -// Warn if we try to give an instantiation visibility after it's already +// Don't warn if we give an instantiation visibility after it's already // been instantiated. // { dg-require-visibility "" } +// { dg-final { scan-hidden "_ZN1AIdE1fEd" } } template <class T> struct A { void f (T); }; template <class T> void A<T>::f (T) { } A<double> ad; -template struct __attribute ((visibility ("hidden"))) A<double>; // { dg-warning "already defined" } +template struct __attribute ((visibility ("hidden"))) A<double>; -- 2.11.0