OSDN Git Service

* pt.c (check_explicit_specialization): Add visibility logic.
authormrs <mrs@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 28 Jul 2005 18:06:47 +0000 (18:06 +0000)
committermrs <mrs@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 28 Jul 2005 18:06:47 +0000 (18:06 +0000)
        (lookup_template_class): Likewise.
        (instantiate_class_template): Likewise.

        * g++.old-deja/g++.mike/visibility-1.C: New test.
Radar 4182971.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102499 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.mike/visibility-1.C [new file with mode: 0644]

index da39c84..31e3d97 100644 (file)
@@ -1,3 +1,9 @@
+2005-07-28  Mike Stump  <mrs@apple.com>
+
+       * pt.c (check_explicit_specialization): Add visibility logic.
+       (lookup_template_class): Likewise.
+       (instantiate_class_template): Likewise.
+
 2005-07-27  Devang Patel  <dpatel@apple.com>
 
        * name-lookup.c (pushtag): Do no set DECL_IGNORED_P bit.
index 2ab89b2..3403e8b 100644 (file)
@@ -2087,6 +2087,14 @@ check_explicit_specialization (tree declarator,
          TREE_PRIVATE (decl) = TREE_PRIVATE (gen_tmpl);
          TREE_PROTECTED (decl) = TREE_PROTECTED (gen_tmpl);
 
+         /* The specialization has the same visibility as the
+            template it specializes.  */
+         if (DECL_VISIBILITY_SPECIFIED (gen_tmpl))
+           {
+             DECL_VISIBILITY_SPECIFIED (decl) = 1;
+             DECL_VISIBILITY (decl) = DECL_VISIBILITY (gen_tmpl);
+           }
+
          if (is_friend && !have_def)
            /* This is not really a declaration of a specialization.
               It's just the name of an instantiation.  But, it's not
@@ -4606,6 +4614,11 @@ lookup_template_class (tree d1,
        = TREE_PROTECTED (TYPE_STUB_DECL (template_type));
       DECL_IN_SYSTEM_HEADER (type_decl)
        = DECL_IN_SYSTEM_HEADER (template);
+      if (CLASSTYPE_VISIBILITY_SPECIFIED (template_type))
+       {
+         DECL_VISIBILITY_SPECIFIED (type_decl) = 1;
+         DECL_VISIBILITY (type_decl) = CLASSTYPE_VISIBILITY (template_type);
+       }
 
       /* Set up the template information.  We have to figure out which
         template is the immediate parent if this is a full
@@ -5525,6 +5538,11 @@ instantiate_class_template (tree type)
   TYPE_FOR_JAVA (type) = TYPE_FOR_JAVA (pattern); /* For libjava's JArray<T> */
   if (ANON_AGGR_TYPE_P (pattern))
     SET_ANON_AGGR_TYPE_P (type);
+  if (CLASSTYPE_VISIBILITY_SPECIFIED (pattern))
+    {
+      CLASSTYPE_VISIBILITY_SPECIFIED (type) = 1;
+      CLASSTYPE_VISIBILITY (type) = CLASSTYPE_VISIBILITY (pattern);
+    }
 
   pbinfo = TYPE_BINFO (pattern);
 
index b52b92e..64fa8fe 100644 (file)
@@ -1,3 +1,7 @@
+2005-07-28  Mike Stump  <mrs@apple.com>
+
+       * g++.old-deja/g++.mike/visibility-1.C: New test.
+
 2005-07-28  Richard Sandiford  <richard@codesourcery.com>
 
        PR c/20187
diff --git a/gcc/testsuite/g++.old-deja/g++.mike/visibility-1.C b/gcc/testsuite/g++.old-deja/g++.mike/visibility-1.C
new file mode 100644 (file)
index 0000000..40e7427
--- /dev/null
@@ -0,0 +1,22 @@
+/* Test visibility attribute on template member function
+   instantiations. */
+
+/* { dg-do compile } */
+/* { dg-options "-fvisibility=hidden" } */
+/* { dg-require-visibility "" } */
+/* { dg-final { scan-not-hidden "_ZN7myClassIiE3maxEii" } } */
+
+#define EXPORT __attribute__((visibility("default")))
+
+template <class T>
+class EXPORT myClass {
+public:
+  T max (T t1, T t2);
+};
+
+template <class T>
+T myClass<T>::max (T t1, T t2) {
+  return (t1 > t2 ? t1 : t2);
+}
+
+template class myClass<int>;