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: Fix PR/7621


This patch fixes C++ PR/7621, a regression from GCC-2.95.x, where we failed to
check for the cases where lookup_member() returns a null tree.
It would be better if lookup_member could always diagnose failures, but other
parts of the compiler currently do depend on an Heisenberg behaviour.  Ugh.

Bootstrapped and tested on an i686-pc-linux.  Mainline.

-- Gaby

2002-08-17  Gabriel Dos Reis  <gdr@integrable-solutions.net>

	Fix PR/7621
	* typeck.c (finish_class_member_access_expr): Diagnose cases where
	name lookup finds nothing.

Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.422
diff -p -r1.422 typeck.c
*** cp/typeck.c	15 Aug 2002 10:34:03 -0000	1.422
--- cp/typeck.c	17 Aug 2002 12:24:23 -0000
*************** finish_class_member_access_expr (tree ob
*** 2147,2153 ****
  	  /* Look up the member.  */
  	  member = lookup_member (access_path, name, /*protect=*/1, 
  				  /*want_type=*/0);
! 	  if (member == error_mark_node)
  	    return error_mark_node;
  	}
        else if (TREE_CODE (name) == BIT_NOT_EXPR)
--- 2147,2158 ----
  	  /* Look up the member.  */
  	  member = lookup_member (access_path, name, /*protect=*/1, 
  				  /*want_type=*/0);
! 	  if (member == NULL_TREE)
! 	    {
! 	      error ("'%D' has no member named '%E'", object_type, name);
! 	      return error_mark_node;
! 	    }
! 	  else if (member == error_mark_node)
  	    return error_mark_node;
  	}
        else if (TREE_CODE (name) == BIT_NOT_EXPR)
*************** finish_class_member_access_expr (tree ob
*** 2171,2177 ****
  	  /* An unqualified name.  */
  	  member = lookup_member (object_type, name, /*protect=*/1, 
  				  /*want_type=*/0);
! 	  if (member == error_mark_node)
  	    return error_mark_node;
  	}
        else
--- 2176,2187 ----
  	  /* An unqualified name.  */
  	  member = lookup_member (object_type, name, /*protect=*/1, 
  				  /*want_type=*/0);
! 	  if (member == NULL_TREE)
! 	    {
! 	      error ("'%D' has no member named '%E'", object_type, name);
! 	      return error_mark_node;
! 	    }
! 	  else if (member == error_mark_node)
  	    return error_mark_node;
  	}
        else
Index: testsuite/g++.dg/lookup/class-member-1.C
===================================================================
RCS file: testsuite/g++.dg/lookup/class-member-1.C
diff -N testsuite/g++.dg/lookup/class-member-1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/lookup/class-member-1.C	17 Aug 2002 12:24:24 -0000
***************
*** 0 ****
--- 1,11 ----
+ // Copyright (C) 2002 Free Software Foundation
+ // Origin: PR/7621, Vaclav.Haisman@logout.sh.cvut.cz
+ // Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
+ 
+ struct A { };
+ 
+ int main()
+ {
+   A a;
+   a.i = 9;           // { dg-error "no member" "" }
+ }


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