C++ PATCH: PR 7224

Mark Mitchell mark@codesourcery.com
Thu Jul 11 15:40:00 GMT 2002


This is a patch for a high-priority PR; a regression whereby we
stopped issuing messages about an egregious error.

We get to simplify our code a bit...

Tested on i686-pc-linux-gnu, applied on the mainline and on the
branch.

-- 
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2002-07-11  Mark Mitchell  <mark@codesourcery.com>

	PR c++/7224
	* class.c (add_method): Simplify.

2002-07-11  Mark Mitchell  <mark@codesourcery.com>

	PR c++/7224
	* g++.dg/overload/error1.C: New test.
	
Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.436.2.8
diff -c -p -r1.436.2.8 class.c
*** class.c	16 May 2002 02:09:11 -0000	1.436.2.8
--- class.c	11 Jul 2002 21:54:10 -0000
*************** add_method (type, method, error_p)
*** 973,1041 ****
  	   fns = OVL_NEXT (fns))
  	{
  	  tree fn = OVL_CURRENT (fns);
! 		 
  	  if (TREE_CODE (fn) != TREE_CODE (method))
  	    continue;
  
! 	  if (TREE_CODE (method) != TEMPLATE_DECL)
  	    {
! 	      /* [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
! 			error ("`%#D' and `%#D' cannot be overloaded",
! 				  fn, method);
! 		    }
  		}
  	    }
- 
- 	  if (!decls_match (fn, method))
- 	    continue;
- 
- 	  /* There has already been a declaration of this method
- 	     or member template.  */
- 	  cp_error_at ("`%D' has already been declared in `%T'", 
- 		       method, type);
- 
- 	  /* We don't call duplicate_decls here to merge the
- 	     declarations because that will confuse things if the
- 	     methods have inline definitions.  In particular, we
- 	     will crash while processing the definitions.  */
- 	  return;
  	}
      }
  
--- 973,1029 ----
  	   fns = OVL_NEXT (fns))
  	{
  	  tree fn = OVL_CURRENT (fns);
! 	  tree parms1;
! 	  tree parms2;
! 	  bool same = 1;
! 
  	  if (TREE_CODE (fn) != TREE_CODE (method))
  	    continue;
  
! 	  /* [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).  */
! 	  parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
! 	  parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
! 
! 	  /* 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 (! 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
  		{
! 		  cp_error_at ("`%#D' and `%#D' cannot be overloaded",
! 			       method, fn, method);
! 
! 		  /* We don't call duplicate_decls here to merge
! 		     the declarations because that will confuse
! 		     things if the methods have inline
! 		     definitions.  In particular, we will crash
! 		     while processing the definitions.  */
! 		  return;
  		}
  	    }
  	}
      }
  
Index: error1.C
===================================================================
RCS file: error1.C
diff -N error1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- error1.C	11 Jul 2002 22:05:38 -0000
***************
*** 0 ****
--- 1,7 ----
+ // { dg-do compile }
+ 
+ struct S
+ {
+   void f () {}
+   int f () { return 0; } // { dg-error "" "" }
+ };



More information about the Gcc-patches mailing list