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 to lookup ambiguity detection


As in g++.other/lookup21.C, a lookup that finds the same static member
functions in multiple subobjects is not ambiguous.

2001-02-08  Jason Merrill  <jason@redhat.com>

	* search.c (shared_member_p): New function.
	(lookup_field_r): Use it.
	* cp-tree.h (SHARED_MEMBER_P): Remove.

*** search.c.~1~	Thu Feb  8 12:43:04 2001
--- search.c	Thu Feb  8 12:43:06 2001
*************** static tree bfs_walk
*** 119,124 ****
--- 119,125 ----
  	PARAMS ((tree, tree (*) (tree, void *), tree (*) (tree, void *),
  	       void *));
  static tree lookup_field_queue_p PARAMS ((tree, void *));
+ static int shared_member_p PARAMS ((tree));
  static tree lookup_field_r PARAMS ((tree, void *));
  static tree canonical_binfo PARAMS ((tree));
  static tree shared_marked_p PARAMS ((tree, void *));
*************** template_self_reference_p (type, decl)
*** 1312,1317 ****
--- 1313,1349 ----
  	   && DECL_NAME (decl) == constructor_name (type));
  }
  
+ 
+ /* Nonzero for a class member means that it is shared between all objects
+    of that class.
+ 
+    [class.member.lookup]:If the resulting set of declarations are not all
+    from sub-objects of the same type, or the set has a  nonstatic  member
+    and  includes members from distinct sub-objects, there is an ambiguity
+    and the program is ill-formed.
+ 
+    This function checks that T contains no nonstatic members.  */
+ 
+ static int
+ shared_member_p (t)
+      tree t;
+ {
+   if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == TYPE_DECL \
+       || TREE_CODE (t) == CONST_DECL)
+     return 1;
+   if (is_overloaded_fn (t))
+     {
+       for (; t; t = OVL_NEXT (t))
+ 	{
+ 	  tree fn = OVL_CURRENT (t);
+ 	  if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
+ 	    return 0;
+ 	}
+       return 1;
+     }
+   return 0;
+ }
+ 
  /* DATA is really a struct lookup_field_info.  Look for a field with
     the name indicated there in BINFO.  If this function returns a
     non-NULL value it is the result of the lookup.  Called from
*************** lookup_field_r (binfo, data)
*** 1392,1398 ****
       hide the old one, we might have an ambiguity.  */
    if (lfi->rval_binfo && !is_subobject_of_p (lfi->rval_binfo, binfo, lfi->type))
      {
!       if (nval == lfi->rval && SHARED_MEMBER_P (nval))
  	/* The two things are really the same.  */
  	;
        else if (is_subobject_of_p (binfo, lfi->rval_binfo, lfi->type))
--- 1424,1430 ----
       hide the old one, we might have an ambiguity.  */
    if (lfi->rval_binfo && !is_subobject_of_p (lfi->rval_binfo, binfo, lfi->type))
      {
!       if (nval == lfi->rval && shared_member_p (nval))
  	/* The two things are really the same.  */
  	;
        else if (is_subobject_of_p (binfo, lfi->rval_binfo, lfi->type))
*** cp-tree.h.~1~	Thu Feb  8 12:43:03 2001
--- cp-tree.h	Thu Feb  8 12:43:05 2001
*************** struct lang_decl
*** 2070,2081 ****
     member function.  */
  #define DECL_STATIC_FUNCTION_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.static_function)
  
- /* Nonzero for a class member means that it is shared between all objects
-    of that class.  */
- #define SHARED_MEMBER_P(NODE) \
-   (TREE_CODE (NODE) == VAR_DECL || TREE_CODE (NODE) == TYPE_DECL \
-    || TREE_CODE (NODE) == CONST_DECL)
- 
  /* Nonzero for FUNCTION_DECL means that this decl is a non-static
     member function.  */
  #define DECL_NONSTATIC_MEMBER_FUNCTION_P(NODE) \
--- 2070,2075 ----

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