Patchwork C++ PATCH for c++/54883 (link conflict with enum in anon namespace)

login
register
mail settings
Submitter Jason Merrill
Date Dec. 11, 2012, 10:42 p.m.
Message ID <50C7B6D1.8040809@redhat.com>
Download mbox | patch
Permalink /patch/205327/
State New
Headers show

Comments

Jason Merrill - Dec. 11, 2012, 10:42 p.m.
Enums in anonymous namespace should get anon visibility just like classes.

Tested x86_64-pc-linux-gnu, applying to 4.6, 4.7 and trunk.

Patch

commit ebb0d2ecbf7717afcb45f52ab7d7a0d68ae2157b
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Dec 11 16:34:24 2012 -0500

    	PR c++/54883
    	* decl2.c (min_vis_r): Handle anon visibility for enums.

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index fd54cac..c5de37e 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1926,16 +1926,15 @@  min_vis_r (tree *tp, int *walk_subtrees, void *data)
     {
       *walk_subtrees = 0;
     }
-  else if (CLASS_TYPE_P (*tp))
+  else if (TAGGED_TYPE_P (*tp)
+	   && !TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
     {
-      if (!TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
-	{
-	  *vis_p = VISIBILITY_ANON;
-	  return *tp;
-	}
-      else if (CLASSTYPE_VISIBILITY (*tp) > *vis_p)
-	*vis_p = CLASSTYPE_VISIBILITY (*tp);
+      *vis_p = VISIBILITY_ANON;
+      return *tp;
     }
+  else if (CLASS_TYPE_P (*tp)
+	   && CLASSTYPE_VISIBILITY (*tp) > *vis_p)
+    *vis_p = CLASSTYPE_VISIBILITY (*tp);
   return NULL;
 }
 
diff --git a/gcc/testsuite/g++.dg/abi/anon1.C b/gcc/testsuite/g++.dg/abi/anon1.C
new file mode 100644
index 0000000..c45917a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/anon1.C
@@ -0,0 +1,5 @@ 
+// PR c++/54883
+
+namespace { enum E { E1 }; } void f(E e) { }
+
+// { dg-final { scan-assembler-not "globl" } }