mangle.c (write_mangled_name, [...]): Mangle overloaded operators even in "C" linkage.

* 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
This commit is contained in:
Jakub Jelinek 2001-01-25 08:35:21 +01:00 committed by Jakub Jelinek
parent cf480ba7da
commit 324ffb8c3d
6 changed files with 67 additions and 4 deletions

View 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.

View 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);

View 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;
}

View 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))

View 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.

View file

@ -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();
}