re PR c++/34213 (static member function in anonymous namespace can't be used as templ...
authorJakub Jelinek <jakub@gcc.gnu.org>
Tue, 27 Nov 2007 07:12:10 +0000 (08:12 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 27 Nov 2007 07:12:10 +0000 (08:12 +0100)
PR c++/34213
* tree.c (decl_linkage): Static data members and static member
functions in anonymous ns classes are lk_external.

* g++.dg/ext/visibility/anon8.C: New test.

From-SVN: r130463

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/visibility/anon8.C [new file with mode: 0644]

index 293238e..37e7a3c 100644 (file)
@@ -1,6 +1,12 @@
+2007-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/34213
+       * tree.c (decl_linkage): Static data members and static member
+       functions in anonymous ns classes are lk_external.
+
 2007-11-26  Andreas Krebbel  <krebbel1@de.ibm.com>
 
-       PR 34081/C++
+       PR c++/34081
        * decl.c (start_preparsed_function): Pass 
        processing_template_decl for the new allocate_struct_function
        parameter.
index 252195d..6ae0568 100644 (file)
@@ -2526,10 +2526,18 @@ decl_linkage (tree decl)
   /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
      are considered to have external linkage for language purposes.  DECLs
      really meant to have internal linkage have DECL_THIS_STATIC set.  */
-  if (TREE_CODE (decl) == TYPE_DECL
-      || ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
-         && !DECL_THIS_STATIC (decl)))
+  if (TREE_CODE (decl) == TYPE_DECL)
     return lk_external;
+  if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
+    {
+      if (!DECL_THIS_STATIC (decl))
+       return lk_external;
+
+      /* Static data members and static member functions from classes
+        in anonymous namespace also don't have TREE_PUBLIC set.  */
+      if (DECL_CLASS_CONTEXT (decl))
+       return lk_external;
+    }
 
   /* Everything else has internal linkage.  */
   return lk_internal;
index 5363cf2..10ce3a5 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/34213
+       * g++.dg/ext/visibility/anon8.C: New test.
+
 2007-11-13  Michael Meissner  <michael.meissner@amd.com>
 
        PR target/34077
@@ -22,7 +27,7 @@
 
 2007-11-26  Andreas Krebbel  <krebbel1@de.ibm.com>
 
-       PR 34081/C++
+       PR c++/34081
        * g++.dg/template/dependent-expr6.C: New testcase.
 
 2007-11-26  Uros Bizjak  <ubizjak@gmail.com>
diff --git a/gcc/testsuite/g++.dg/ext/visibility/anon8.C b/gcc/testsuite/g++.dg/ext/visibility/anon8.C
new file mode 100644 (file)
index 0000000..827cc22
--- /dev/null
@@ -0,0 +1,33 @@
+// PR c++/34213
+// { dg-do compile }
+
+template <void (*fn) ()>
+void call ()
+{
+  fn ();
+}
+
+namespace
+{
+  struct B1
+  {
+    static void fn1 () {}
+    static void fn4 ();
+  };
+  void fn3 () {}
+  void B1::fn4 () {}
+  static void fn5 () {}
+}
+
+int main ()
+{
+  struct B2
+  {
+    static void fn2 () {}
+  };
+  call<&B1::fn1> ();
+  call<&B2::fn2> ();   // { dg-error "not external linkage|no matching" }
+  call<&fn3> ();
+  call<&B1::fn4> ();
+  call<&fn5> ();       // { dg-error "not external linkage|no matching" }
+}