This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Namespaces and in class defined friends
- To: kurt at garloff dot de
- Subject: Re: Namespaces and in class defined friends
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Mon, 14 Jun 1999 11:31:31 +0200
- CC: egcs-bugs at egcs dot cygnus dot com
- References: <19990519231922.A23467@kurt.kdt.de>
[Kurt: The first copy was returned because it went to @cygnus.com]
> I stumbled across a problem with my numerical library in C++. I recently
> converted to using namespaces all over the place and while concetually
> simple, it seems there are problems.
Thanks for your bug report. The problem was that instantiation of the
template friend would overwrite the pointer to the global
function. Here is a patch.
Ok to install in both branches?
Regards,
Martin
1999-06-14 Martin von Löwis <loewis@informatik.hu-berlin.de>
* pt.c (tsubst_friend_function): Push into namespace of friend
function before pushdecl'ing it.
void foo(){}
namespace Bar{
template<class X>
class Y{
friend void foo(Y<X>){}
};
}
int main()
{
Bar::Y<int> y;
foo(y);
foo();
}
Index: pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.306
diff -c -p -r1.306 pt.c
*** pt.c 1999/05/25 15:31:36 1.306
--- pt.c 1999/06/14 09:05:25
*************** tsubst_friend_function (decl, args)
*** 4495,4500 ****
--- 4495,4501 ----
tree old_decl;
tree new_friend_template_info;
tree new_friend_result_template_info;
+ tree ns;
int new_friend_is_defn;
/* We must save some information from NEW_FRIEND before calling
*************** tsubst_friend_function (decl, args)
*** 4517,4523 ****
--- 4518,4530 ----
new_friend_result_template_info = NULL_TREE;
}
+ /* Inside pushdecl_namespace_level, we will push into the
+ current namespace. However, the friend function should
+ tyically go into the namespace of the template. */
+ ns = decl_namespace_context (new_friend);
+ push_nested_namespace (ns);
old_decl = pushdecl_namespace_level (new_friend);
+ pop_nested_namespace (ns);
if (old_decl != new_friend)
{