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]

[C++ PATCH for 3.3.2] Fix PR12369 (ICE specialization of memberfunction as friend)


Hi

We have a regression PR12369 in 3.3 branch.  It's an ICE
processing friend declaration of the form:

	class A {
	  friend void B::b<T>();
	};

inside non-template class 'A'.

And it turns out that the patch I installed in the main trunk back
in July for PR5421

	http://gcc.gnu.org/ml/gcc-patches/2003-07/msg01682.html

is the right fix to this bug.  (The difference between the 2 reports
is whether the enclosing class like 'A' is a template or not.
PR5421 is not a regression.)

Below is the patch I revise for 3.3, replacing PR5421 testcase (which
also depends on other changes in 3.4) with PR12369 testcase.  I think
this patch is a good candidate for 3.3.2.

Tested on i686-pc-linux-gnu.  OK to commit to 3.3 branch?

--Kriang


2003-09-24  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/12369
	* decl.c (grokdeclarator): Handle TEMPLATE_ID_EXPR if friend
	is a member of other class.
	* friend.c (do_friend): Don't build TEMPLATE_DECL if friend
	is a specialization of function template.

2003-09-24  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/12369
	* g++.dg/template/friend25.C: New test.


diff -cprN gcc-33-save/gcc/cp/decl.c gcc-33-new/gcc/cp/decl.c
*** gcc-33-save/gcc/cp/decl.c	Mon Sep 15 21:12:29 2003
--- gcc-33-new/gcc/cp/decl.c	Tue Sep 23 21:56:17 2003
*************** grokdeclarator (declarator, declspecs, d
*** 12337,12343 ****
  	       members of other classes.  */
  	    /* All method decls are public, so tell grokfndecl to set
  	       TREE_PUBLIC, also.  */
! 	    decl = grokfndecl (ctype, type, declarator, declarator,
  			       virtualp, flags, quals, raises,
  			       friendp ? -1 : 0, friendp, 1, 0, funcdef_flag,
  			       template_count, in_namespace);
--- 12337,12346 ----
  	       members of other classes.  */
  	    /* All method decls are public, so tell grokfndecl to set
  	       TREE_PUBLIC, also.  */
! 	    decl = grokfndecl (ctype, type,
! 			       TREE_CODE (declarator) != TEMPLATE_ID_EXPR
! 			       ? declarator : dname,
! 			       declarator,
  			       virtualp, flags, quals, raises,
  			       friendp ? -1 : 0, friendp, 1, 0, funcdef_flag,
  			       template_count, in_namespace);
diff -cprN gcc-33-save/gcc/cp/friend.c gcc-33-new/gcc/cp/friend.c
*** gcc-33-save/gcc/cp/friend.c	Fri Jan 31 19:21:51 2003
--- gcc-33-new/gcc/cp/friend.c	Tue Sep 23 21:56:17 2003
*************** do_friend (ctype, declarator, decl, parm
*** 352,357 ****
--- 352,359 ----
  
        if (is_friend_template)
  	decl = DECL_TI_TEMPLATE (push_template_decl (decl));
+       else if (DECL_TEMPLATE_INFO (decl))
+ 	;
        else if (template_class_depth (current_class_type))
  	decl = push_template_decl_real (decl, /*is_friend=*/1);
  
diff -cprN gcc-33-save/gcc/testsuite/g++.dg/template/friend25.C gcc-33-new/gcc/testsuite/g++.dg/template/friend25.C
*** gcc-33-save/gcc/testsuite/g++.dg/template/friend25.C	Thu Jan  1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/template/friend25.C	Wed Sep 24 21:04:18 2003
***************
*** 0 ****
--- 1,14 ----
+ // { dg-do compile }
+ 
+ // Origin: Jiangbin Zhao <zhaojiangbin@yahoo.com>
+ 
+ // PR c++/12369: ICE for specialization of member function template
+ // as friend in ordinary class.
+ 
+ struct A {
+     template<class T> T* make() { return new T(); }
+ };
+  
+ struct B {
+     friend B* A::make< B >(); // (1)
+ };


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