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 PR10230, 10481 (a regression in trunk)


Hi

When parsing a nested name like 'A::a' inside some class 'C' and the
member 'a' is non-static, we fail to take into account that 'C' may
not contain 'A' as its base class.  More specifically, the 'access_type'
may become NULL_TREE inside the while loop in 'finish_non_static_data_member'.
This is a regression in the main trunk reported in PR 10230, and 10481.
It is fixed by the appended patch.

Tested on i686-pc-linux-gnu.  OK to commit to the trunk?

--Kriang


2003-04-27  Kriang Lerdsuwanakij  <lerdsuwa at users dot sourceforge dot net>

	* semantics.c (finish_non_static_data_member): Handle when the
	non-static member is not from a base of the current class type.

2003-04-27  Kriang Lerdsuwanakij  <lerdsuwa at users dot sourceforge dot net>

	* g++.dg/lookup/scoped5.C: New test.


diff -cprN gcc-main-save/gcc/cp/semantics.c gcc-main-new/gcc/cp/semantics.c
*** gcc-main-save/gcc/cp/semantics.c	Mon Apr 14 17:00:20 2003
--- gcc-main-new/gcc/cp/semantics.c	Sat Apr 26 23:49:36 2003
*************** finish_non_static_data_member (tree decl
*** 1213,1225 ****
        tree access_type = current_class_type;
        tree object = current_class_ref;
  
!       while (!DERIVED_FROM_P (context_for_name_lookup (decl), access_type))
  	{
  	  access_type = TYPE_CONTEXT (access_type);
! 	  while (DECL_P (access_type))
  	    access_type = DECL_CONTEXT (access_type);
  	}
  
        enforce_access (access_type, decl);
  
        /* If the data member was named `C::M', convert `*this' to `C'
--- 1213,1234 ----
        tree access_type = current_class_type;
        tree object = current_class_ref;
  
!       while (access_type
! 	     && !DERIVED_FROM_P (context_for_name_lookup (decl), access_type))
  	{
  	  access_type = TYPE_CONTEXT (access_type);
! 	  while (access_type && DECL_P (access_type))
  	    access_type = DECL_CONTEXT (access_type);
  	}
  
+       if (!access_type)
+ 	{
+ 	  cp_error_at ("`%D' is neither static nor member of base type of `%T'",
+ 		       decl, current_class_type);
+ 	  error ("from this location");
+ 	  return error_mark_node;
+ 	}
+ 
        enforce_access (access_type, decl);
  
        /* If the data member was named `C::M', convert `*this' to `C'
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/lookup/scoped5.C gcc-main-new/gcc/testsuite/g++.dg/lookup/scoped5.C
*** gcc-main-save/gcc/testsuite/g++.dg/lookup/scoped5.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/lookup/scoped5.C	Sat Apr 26 23:51:51 2003
***************
*** 0 ****
--- 1,19 ----
+ // { dg-do compile }
+ 
+ // Origin: pepeaty at yahoo dot com
+ 
+ // PR c++/10230: ICE while determining if refered non-static member
+ // is from a base type of the current class.
+ 
+ class A {
+ public:
+   class B {
+   public:
+     int a;			// { dg-error "member of base" }
+   };
+ };
+ 
+ class C {
+ public:
+   void f(void) { sizeof(A::B::a); } // { dg-error "this location" }
+ };


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