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]

PATCH for crash on illegal template friend declaration



Here's a patch for an ICE on bogus code.

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

1998-08-30  Mark Mitchell  <mark@markmitchell.com>

	* decl.c (grokfndecl): Issue error on declaration of friend
	templates with explicit template arguments.

Index: testsuite/g++.old-deja/g++.pt/crash23.C
===================================================================
RCS file: crash23.C
diff -N crash23.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- crash23.C	Sun Aug 30 11:41:58 1998
***************
*** 0 ****
--- 1,15 ----
+ // Build don't link:
+ 
+ template <class A, class B> void foo();
+ template <class C> class bar {
+   int i;
+   template <class B> friend void foo<C,B>(); // ERROR - template-id
+ };
+ template <class A, class B> void foo() {
+   bar<A> baz; baz.i = 1;
+   bar<int> buz; buz.i = 1;
+ }
+ int main() {
+   foo<void,void>();
+   foo<int,void>();
+ }
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.198
diff -c -p -r1.198 decl.c
*** decl.c	1998/08/28 15:43:53	1.198
--- decl.c	1998/08/30 18:42:42
*************** grokfndecl (ctype, type, declarator, ori
*** 7968,7973 ****
--- 7968,7981 ----
  	   orig_declarator);
        else
  	{
+ 	  if (PROCESSING_REAL_TEMPLATE_DECL_P ())
+ 	    {
+ 	      /* Something like `template <class T> friend void f<T>()'.  */
+ 	      cp_error ("template-id `%D' in declaration of primary template", 
+ 			orig_declarator);
+ 	      return error_mark_node;
+ 	    }
+ 
  	  /* A friend declaration of the form friend void f<>().  Record
  	     the information in the TEMPLATE_ID_EXPR.  */
  	  SET_DECL_IMPLICIT_INSTANTIATION (decl);


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