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 for field lookup


Since we now do a binary search to find fields in large classes, a
member name lookup might find a nested type that is supposed to be
hidden by another field.  This patch fixes that behavior
(g++.other/lookup17.C).

2000-01-06  Jason Merrill  <jason@casey.cygnus.com>

	* class.c (field_decl_cmp): A nontype is "greater" than a type.
	* search.c (lookup_field_1): Look for the last field with the
	desired name.

Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/class.c,v
retrieving revision 1.223
diff -c -p -r1.223 class.c
*** class.c	2000/01/04 16:29:41	1.223
--- class.c	2000/01/06 23:31:29
*************** field_decl_cmp (x, y)
*** 1946,1952 ****
       const tree *x, *y;
  {
    if (DECL_NAME (*x) == DECL_NAME (*y))
!     return 0;
    if (DECL_NAME (*x) == NULL_TREE)
      return -1;
    if (DECL_NAME (*y) == NULL_TREE)
--- 1946,1953 ----
       const tree *x, *y;
  {
    if (DECL_NAME (*x) == DECL_NAME (*y))
!     /* A nontype is "greater" than a type.  */
!     return DECL_DECLARES_TYPE_P (*y) - DECL_DECLARES_TYPE_P (*x);
    if (DECL_NAME (*x) == NULL_TREE)
      return -1;
    if (DECL_NAME (*y) == NULL_TREE)
Index: search.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/search.c,v
retrieving revision 1.141
diff -c -p -r1.141 search.c
*** search.c	2000/01/03 21:32:58	1.141
--- search.c	2000/01/06 23:31:31
*************** lookup_field_1 (type, name)
*** 611,617 ****
  	  else if (DECL_NAME (fields[i]) < name)
  	    lo = i + 1;
  	  else
! 	    return fields[i];
  	}
        return NULL_TREE;
      }
--- 611,626 ----
  	  else if (DECL_NAME (fields[i]) < name)
  	    lo = i + 1;
  	  else
! 	    {
! 	      /* We might have a nested class and a field with the
! 		 same name; we sorted them appropriately via
! 		 field_decl_cmp, so just look for the last field with
! 		 this name.  */
! 	      while (i + 1 < hi
! 		     && DECL_NAME (fields[i+1]) == name)
! 		++i;
! 	      return fields[i];
! 	    }
  	}
        return NULL_TREE;
      }

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