This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH to tsubst_friend_function for c++/19809


In 19809 we were assuming that the function we are creating is always the first definition, blithely clobbering any previous definition. Fixed by setting DECL_INITIAL before calling pushdecl.

Tested x86_64-pc-linux-gnu, applied to trunk.

2006-09-05  Jason Merrill  <jason@redhat.com>

	PR c++/19809
	* pt.c (tsubst_friend_function): Set DECL_INITIAL before pushdecl.

Index: cp/pt.c
===================================================================
*** cp/pt.c	(revision 116703)
--- cp/pt.c	(working copy)
*************** tsubst_friend_function (tree decl, tree 
*** 5333,5338 ****
--- 5333,5342 ----
        else
  	new_friend_result_template_info = NULL_TREE;
  
+       /* Make the init_value nonzero so pushdecl knows this is a defn.  */
+       if (new_friend_is_defn)
+ 	DECL_INITIAL (new_friend) = error_mark_node;
+ 
        /* Inside pushdecl_namespace_level, we will push into the
  	 current namespace. However, the friend function should go
  	 into the namespace of the template.  */
Index: testsuite/g++.dg/template/friend47.C
===================================================================
*** testsuite/g++.dg/template/friend47.C	(revision 0)
--- testsuite/g++.dg/template/friend47.C	(revision 0)
***************
*** 0 ****
--- 1,11 ----
+ // PR c++/19809
+ 
+ template<int i>
+ struct n{
+   friend void foo(){ }		// { dg-error "defin" }
+ };
+ 
+ int main(){
+   n<1> n1;
+   n<2> n2;
+ }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]