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] Friend class and DR 180


Hi

The following patch fixes a friend class issue relating to DR 180.
We currently accept the code
	friend typename A::B;
but according to DR 180, the correct syntax should be
	friend class A::B;
and no 'typename' keyword is allowed there.  So a class-key is always
required for a friend class declaration.

The error message issued for the above incorrect code is wrong as
well.  This too is addressed in the patch.

Bootstrapped and tested on i686-pc-linux-gnu with no regressions.
OK to commit to main trunk?

--Kriang


2002-11-26  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	DR 180
	* decl.c (grokdeclarator): Require class-key for all friend class.
	Output the correct context in the error message.

2002-11-26  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	DR 180
	* g++.old-deja/g++.pt/crash32.C: Expect error.


diff -cprN gcc-main-save/gcc/cp/decl.c gcc-main-new/gcc/cp/decl.c
*** gcc-main-save/gcc/cp/decl.c	Thu Oct 31 20:53:28 2002
--- gcc-main-new/gcc/cp/decl.c	Tue Nov 26 14:24:30 2002
*************** grokdeclarator (declarator, declspecs, d
*** 11635,11651 ****
  	      inlinep = 0;
  	    }

! 	  /* Until core issue 180 is resolved, allow 'friend typename A::B'.
! 	     But don't allow implicit typenames except with a class-key.  */
! 	  if (!current_aggr && (TREE_CODE (type) != TYPENAME_TYPE
! 				|| IMPLICIT_TYPENAME_P (type)))
  	    {
  	      if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
! 	        pedwarn ("template parameters cannot be friends");
  	      else if (TREE_CODE (type) == TYPENAME_TYPE)
  	        pedwarn ("\
  friend declaration requires class-key, i.e. `friend class %T::%T'",
! 			    constructor_name (current_class_type),
  			    TYPE_IDENTIFIER (type));
  	      else
  	        pedwarn ("\
--- 11635,11649 ----
  	      inlinep = 0;
  	    }

! 	  if (!current_aggr)
  	    {
+ 	      /* Don't allow friend declaration without a class-key.  */
  	      if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
! 		pedwarn ("template parameters cannot be friends");
  	      else if (TREE_CODE (type) == TYPENAME_TYPE)
  	        pedwarn ("\
  friend declaration requires class-key, i.e. `friend class %T::%T'",
! 			    TYPE_IDENTIFIER (TYPE_CONTEXT (type)),
  			    TYPE_IDENTIFIER (type));
  	      else
  	        pedwarn ("\
diff -cprN gcc-main-save/gcc/testsuite/g++.old-deja/g++.pt/crash32.C gcc-main-new/gcc/testsuite/g++.old-deja/g++.pt/crash32.C
*** gcc-main-save/gcc/testsuite/g++.old-deja/g++.pt/crash32.C	Sat Sep  4 22:09:07 1999
--- gcc-main-new/gcc/testsuite/g++.old-deja/g++.pt/crash32.C	Tue Nov 26 14:01:57 2002
*************** template <class T> struct A
*** 8,13 ****

  template<class T> struct C
  {
!   friend typename A<T>::B;
  };

--- 8,13 ----

  template<class T> struct C
  {
!   friend typename A<T>::B; // ERROR - struct is required
  };



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