------- Comment #8 from dodji at gcc dot gnu dot org 2009-10-23 18:19 ------- Subject: Re: [4.5 Regression] Can't declare an extern "C" friend of a builtin function
Indeed. I am testing the patch below. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5eb389f..7c01ee2 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -104,6 +104,7 @@ static void store_parm_decls (tree); static void initialize_local_var (tree, tree); static void expand_static_init (tree, tree); static tree next_initializable_field (tree); +static int decls_match_1 (tree, tree, bool); /* The following symbols are subsumed in the cp_global_trees array, and listed here individually for documentation purposes. @@ -899,6 +900,14 @@ push_local_name (tree decl) int decls_match (tree newdecl, tree olddecl) { + return decls_match_1 (newdecl, olddecl, /* newdecl_is_friend */ false); +} + +/* Subroutine of decls_match. */ + +static int +decls_match_1 (tree newdecl, tree olddecl, bool newdecl_is_friend) +{ int types_match; if (newdecl == olddecl) @@ -934,9 +943,11 @@ decls_match (tree newdecl, tree olddecl) #ifdef NO_IMPLICIT_EXTERN_C /* A new declaration doesn't match a built-in one unless it - is also extern "C". */ + is also extern "C". Friend function re-declarations retain the + the linkage of the original declaration though. */ if (DECL_BUILT_IN (olddecl) - && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl)) + && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl) + && !newdecl_is_friend) return 0; #endif @@ -1122,7 +1133,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) if (newdecl == olddecl) return olddecl; - types_match = decls_match (newdecl, olddecl); + types_match = decls_match_1 (newdecl, olddecl, newdecl_is_friend); /* If either the type of the new decl or the type of the old decl is an error_mark_node, then that implies that we have already issued an -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41020