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 to add_method


When I used the old code for checking static overloads to handle
using-declarations as well, I failed to consider that functions introduced
with a using-declaration can be overloaded on 'this' cv-qualifiers.  Fixed.
Fixes lookup/using.C.

2001-12-18  Jason Merrill  <jason@redhat.com>

	* class.c (add_method): Do compare 'this' quals when trying to match a
	used function.  Don't defer to another used function.

*** class.c.~1~	Tue Dec 18 13:30:57 2001
--- class.c	Tue Dec 18 11:45:19 2001
*************** add_method (type, method, error_p)
*** 972,993 ****
  	      /* [over.load] Member function declarations with the
  		 same name and the same parameter types cannot be
  		 overloaded if any of them is a static member
! 		 function declaration.  */
  	      if ((DECL_STATIC_FUNCTION_P (fn)
  		   != DECL_STATIC_FUNCTION_P (method))
  		  || using)
  		{
  		  tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
  		  tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
  
  		  if (! DECL_STATIC_FUNCTION_P (fn))
  		    parms1 = TREE_CHAIN (parms1);
  		  if (! DECL_STATIC_FUNCTION_P (method))
  		    parms2 = TREE_CHAIN (parms2);
  
! 		  if (compparms (parms1, parms2))
  		    {
! 		      if (using)
  			/* Defer to the local function.  */
  			return;
  		      else
--- 972,1009 ----
  	      /* [over.load] Member function declarations with the
  		 same name and the same parameter types cannot be
  		 overloaded if any of them is a static member
! 		 function declaration.
! 
! 	         [namespace.udecl] When a using-declaration brings names
! 		 from a base class into a derived class scope, member
! 		 functions in the derived class override and/or hide member
! 		 functions with the same name and parameter types in a base
! 		 class (rather than conflicting).  */
  	      if ((DECL_STATIC_FUNCTION_P (fn)
  		   != DECL_STATIC_FUNCTION_P (method))
  		  || using)
  		{
  		  tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
  		  tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
+ 		  int same = 1;
  
+ 		  /* Compare the quals on the 'this' parm.  Don't compare
+ 		     the whole types, as used functions are treated as
+ 		     coming from the using class in overload resolution.  */
+ 		  if (using
+ 		      && ! DECL_STATIC_FUNCTION_P (fn)
+ 		      && ! DECL_STATIC_FUNCTION_P (method)
+ 		      && (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1)))
+ 			  != TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2)))))
+ 		    same = 0;
  		  if (! DECL_STATIC_FUNCTION_P (fn))
  		    parms1 = TREE_CHAIN (parms1);
  		  if (! DECL_STATIC_FUNCTION_P (method))
  		    parms2 = TREE_CHAIN (parms2);
  
! 		  if (same && compparms (parms1, parms2))
  		    {
! 		      if (using && DECL_CONTEXT (fn) == type)
  			/* Defer to the local function.  */
  			return;
  		      else

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