mangle.c (write_mangled_name, [...]): Mangle overloaded operators even in "C" linkage.
authorJakub Jelinek <jakub@redhat.com>
Thu, 25 Jan 2001 07:35:21 +0000 (08:35 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 25 Jan 2001 07:35:21 +0000 (08:35 +0100)
* mangle.c (write_mangled_name, write_encoding): Mangle overloaded
operators even in "C" linkage.
* method.c (set_mangled_name_for_decl): Likewise.
* decl.c (grokfndecl): Call set_mangled_name_for_decl even for
overloaded operators in "C" linkage.

* g++.old-deja/g++.other/mangle2.C: New test.

From-SVN: r39257

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/mangle.c
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.other/mangle2.C [new file with mode: 0644]

index 69ac61d1032a214ab1cb1b2e5412cc42096f9d96..8ba3cc7a0846d5163d41f3291fd804e506fb4558 100644 (file)
@@ -1,3 +1,11 @@
+2001-01-25  Jakub Jelinek  <jakub@redhat.com>
+
+       * mangle.c (write_mangled_name, write_encoding): Mangle overloaded
+       operators even in "C" linkage.
+       * method.c (set_mangled_name_for_decl): Likewise.
+       * decl.c (grokfndecl): Call set_mangled_name_for_decl even for
+       overloaded operators in "C" linkage.
+
 2001-01-24  Nathan Sidwell  <nathan@codesourcery.com>
 
        * pt.c (tsubst_decl): Remove IN_DECL parameter.
index 6fcf9c4d2c2b1acc455863cf3ae9a6914ab43879..761b843b1627f7ecdabd3a22f503a2af158f80c9 100644 (file)
@@ -8846,7 +8846,7 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals,
 
   /* Plain overloading: will not be grok'd by grokclassfn.  */
   if (! ctype && ! processing_template_decl
-      && !DECL_EXTERN_C_P (decl)
+      && (! DECL_EXTERN_C_P (decl) || DECL_OVERLOADED_OPERATOR_P (decl))
       && (! DECL_USE_TEMPLATE (decl) || name_mangling_version < 1))
     set_mangled_name_for_decl (decl);
 
index d0c8e69d068bd6b1fb7a4ac6999220c39348a779..10f0bc8982862faab5bec0c5f0e9be2a7e3bdced 100644 (file)
@@ -602,10 +602,14 @@ write_mangled_name (decl)
 {
   MANGLE_TRACE_TREE ("mangled-name", decl);
 
-  if (DECL_LANG_SPECIFIC (decl) && DECL_EXTERN_C_FUNCTION_P (decl))
+  if (DECL_LANG_SPECIFIC (decl)
+      && DECL_EXTERN_C_FUNCTION_P (decl)
+      && ! DECL_OVERLOADED_OPERATOR_P (decl))
     /* The standard notes:
          "The <encoding> of an extern "C" function is treated like
-        global-scope data, i.e. as its <source-name> without a type."  */
+        global-scope data, i.e. as its <source-name> without a type."
+       We cannot write overloaded operators that way though,
+       because it contains characters invalid in assembler.  */
     write_source_name (DECL_NAME (decl));
   else
     /* C++ name; needs to be mangled.  */
@@ -626,7 +630,12 @@ write_encoding (decl)
 
   if (DECL_LANG_SPECIFIC (decl) && DECL_EXTERN_C_FUNCTION_P (decl))
     {
-      write_source_name (DECL_NAME (decl));
+      /* For overloaded operators write just the mangled name
+        without arguments.  */
+      if (DECL_OVERLOADED_OPERATOR_P (decl))
+       write_name (decl, /*ignore_local_scope=*/0);
+      else
+       write_source_name (DECL_NAME (decl));
       return;
     }
 
index 3e6b3ccf20e252d386a9807ce2f8eb57e999f38d..17016a4a9729e879c89bfa04bb3fa3bac9dcd512 100644 (file)
@@ -1763,6 +1763,24 @@ set_mangled_name_for_decl (decl)
       return;
     }
 
+  if (DECL_EXTERN_C_P (decl))
+    {
+      /* In extern "C" we have to mangle at least overloaded operators,
+        because they contain characters invalid in assembler.  */
+      enum tree_code code = DECL_OVERLOADED_OPERATOR_P (decl);
+      const char *name;
+
+      if (code)
+       {
+         if (DECL_ASSIGNMENT_OPERATOR_P (decl))
+           name = assignment_operator_name_info[(int) code].mangled_name;
+         else
+           name = operator_name_info[(int) code].mangled_name;
+         DECL_ASSEMBLER_NAME (decl) = get_identifier (name);
+         return;
+       }
+    }
+
   parm_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
 
   if (DECL_STATIC_FUNCTION_P (decl))
index c68a93d35f02ec313cfce79034ff230352143aeb..a8352d8a3fe45d88d008a7417bff0a07e75f6772 100644 (file)
@@ -1,3 +1,7 @@
+2001-01-25  Jakub Jelinek  <jakub@redhat.com>
+
+       * g++.old-deja/g++.other/mangle2.C: New test.
+
 2001-01-24  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * gcc.c-torture/compile/20010124-1.c: New test.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/mangle2.C b/gcc/testsuite/g++.old-deja/g++.other/mangle2.C
new file mode 100644 (file)
index 0000000..25bab87
--- /dev/null
@@ -0,0 +1,24 @@
+// Test for overloaded operators in "C" linkage
+// Build don't link:
+
+extern "C" {
+typedef struct b
+{
+  int a;
+} c;
+
+extern const c z;
+
+inline bool operator!=(const c& x, const c& y)
+{
+  return x.a != y.a;
+}
+};
+
+void foo();
+
+void bar(c x)
+{
+  if (x != z)
+    foo();
+}