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]

[C++ PATCH]: Fix bug 1033


Hi,
I've installed this patch for bug 1033 where we'd ICE on a
templated friend not actually being a template.

built & tested on i686-pc-linux-gnu.

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-01-08  Nathan Sidwell  <nathan@codesourcery.com>

	* friend.c (make_friend_class): Make sure a templated class is
	actually a template.

Index: cp/friend.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/friend.c,v
retrieving revision 1.62
diff -c -3 -p -r1.62 friend.c
*** friend.c	2000/09/17 07:38:20	1.62
--- friend.c	2001/01/08 08:55:48
*************** make_friend_class (type, friend_type)
*** 225,256 ****
    else
      is_template_friend = 0;
  
!   if (is_template_friend 
!       && (TREE_CODE (friend_type) == TYPENAME_TYPE
! 	  || TREE_CODE (friend_type) == TEMPLATE_TYPE_PARM))
!     {
!       /* [temp.friend]
! 
! 	   A friend of a class or class template can be a function or
! 	   class template, a specialization of a function template or
! 	   class template, or an ordinary (nontemplate) function or
! 	   class. 
! 	   
! 	 But, we're looking at something like:
! 
! 	   template <class T> friend typename S<T>::X;
! 
! 	 or:
  
! 	   template <class T> friend class T;
! 
! 	 which isn't any of these.  */
!       if (TREE_CODE (friend_type) == TYPENAME_TYPE)
! 	cp_error ("typename type `%T' declared `friend'",
! 		  friend_type);
!       else
! 	cp_error ("template parameter type `%T' declared `friend'",
! 		  friend_type);
        return;
      }
  
--- 225,254 ----
    else
      is_template_friend = 0;
  
!   /* [temp.friend]
  
!      A friend of a class or class template can be a function or
!      class template, a specialization of a function template or
!      class template, or an ordinary (nontemplate) function or
!      class. */
!   if (!is_template_friend)
!     ;/* ok */
!   else if (TREE_CODE (friend_type) == TYPENAME_TYPE)
!     {
!       /* template <class T> friend typename S<T>::X; */
!       cp_error ("typename type `%#T' declared `friend'", friend_type);
!       return;
!     }
!   else if (TREE_CODE (friend_type) == TEMPLATE_TYPE_PARM)
!     {
!       /* template <class T> friend class T; */
!       cp_error ("template parameter type `%T' declared `friend'", friend_type);
!       return;
!     }
!   else if (!CLASSTYPE_TEMPLATE_INFO (friend_type))
!     {
!       /* template <class T> friend class A; where A is not a template */
!       cp_error ("`%#T' is not a template", friend_type);
        return;
      }
  
// Build don't link:

// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 7 Jan 2001 <nathan@codesourcery.com>

// Bug 1033. We ICE'd when trying to make a non template class a templated
// friend.

class A {};
class B {
  template<class T> friend class A;   // ERROR - not a template
};



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