name-lookup.c (get_anonymous_namespace_name): Never use get_file_function_name.
authorJason Merrill <jason@redhat.com>
Thu, 21 Mar 2013 03:25:29 +0000 (23:25 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 21 Mar 2013 03:25:29 +0000 (23:25 -0400)
* name-lookup.c (get_anonymous_namespace_name): Never use
get_file_function_name.

From-SVN: r196851

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/g++.dg/eh/anon1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/eh/anon1a.cc [new file with mode: 0644]
gcc/testsuite/g++.dg/eh/anon2.C [new file with mode: 0644]

index bef6fae..719f70c 100644 (file)
@@ -1,5 +1,8 @@
 2013-03-20  Jason Merrill  <jason@redhat.com>
 
+       * name-lookup.c (get_anonymous_namespace_name): Never use
+       get_file_function_name.
+
        * pt.c (retrieve_specialization): Handle null tmpl argument.
 
        PR c++/17232
index 2a47331..7084a53 100644 (file)
@@ -69,14 +69,12 @@ get_anonymous_namespace_name (void)
 {
   if (!anonymous_namespace_name)
     {
-      /* The anonymous namespace has to have a unique name
-        if typeinfo objects are being compared by name.  */
-      if (! flag_weak || ! SUPPORTS_ONE_ONLY)
-       anonymous_namespace_name = get_file_function_name ("N");
-      else
-       /* The demangler expects anonymous namespaces to be called
-          something starting with '_GLOBAL__N_'.  */
-       anonymous_namespace_name = get_identifier ("_GLOBAL__N_1");
+      /* We used to use get_file_function_name here, but that isn't
+        necessary now that anonymous namespace typeinfos
+        are !TREE_PUBLIC, and thus compared by address.  */
+      /* The demangler expects anonymous namespaces to be called
+        something starting with '_GLOBAL__N_'.  */
+      anonymous_namespace_name = get_identifier ("_GLOBAL__N_1");
     }
   return anonymous_namespace_name;
 }
diff --git a/gcc/testsuite/g++.dg/eh/anon1.C b/gcc/testsuite/g++.dg/eh/anon1.C
new file mode 100644 (file)
index 0000000..2a5ef4b
--- /dev/null
@@ -0,0 +1,26 @@
+// Test that the anonymous namespace isn't mangled with random characters,
+// but also doesn't get mixed up with an anonymous namespace in another
+// translation unit.
+
+// { dg-do run }
+// { dg-additional-sources "anon1a.cc" }
+
+namespace {
+  struct A
+  {
+    virtual void f();
+  };
+
+  void A::f() { }
+}
+
+extern void g();
+
+int main()
+{
+  try {
+    try {
+      g();
+    } catch (A) { __builtin_abort(); }
+  } catch (...) { }
+}
diff --git a/gcc/testsuite/g++.dg/eh/anon1a.cc b/gcc/testsuite/g++.dg/eh/anon1a.cc
new file mode 100644 (file)
index 0000000..ba161ac
--- /dev/null
@@ -0,0 +1,10 @@
+namespace {
+  struct A
+  {
+    virtual void f();
+  };
+
+  void A::f() { }
+}
+
+void g() { throw A(); }
diff --git a/gcc/testsuite/g++.dg/eh/anon2.C b/gcc/testsuite/g++.dg/eh/anon2.C
new file mode 100644 (file)
index 0000000..9ff9ee3
--- /dev/null
@@ -0,0 +1,24 @@
+// Test that the anonymous namespace isn't mangled with random characters,
+// but also doesn't get mixed up with an anonymous namespace in another
+// translation unit.
+// { dg-final { scan-assembler "\\*N12_GLOBAL__N_11AE" } }
+
+namespace {
+  struct A
+  {
+    virtual void f();
+  };
+
+  void A::f() { }
+}
+
+extern void g();
+
+int main()
+{
+  try {
+    try {
+      g();
+    } catch (A) { __builtin_abort(); }
+  } catch (...) { }
+}