public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: James Abbatiello <abbeyj@gmail.com>
To: gcc-patches@gcc.gnu.org
Cc: James Abbatiello <abbeyj@gmail.com>
Subject: [PATCH] PR c++/77306 - Unable to specify visibility for explicit template instantiations
Date: Sat, 22 Apr 2017 23:32:00 -0000	[thread overview]
Message-ID: <20170422204640.47837-1-abbeyj@gmail.com> (raw)

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

             reply	other threads:[~2017-04-22 20:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-22 23:32 James Abbatiello [this message]
2017-05-22  4:37 ` James Abbatiello
2017-05-30 17:50   ` Nathan Sidwell
2017-05-24 19:28 ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170422204640.47837-1-abbeyj@gmail.com \
    --to=abbeyj@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).