+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.
/* 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);
{
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. */
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;
}
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))
+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.
--- /dev/null
+// 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();
+}