C++ PATCH: Remove build_component_ref

Graham Stott graham.stott@btinternet.com
Tue Aug 20 12:23:00 GMT 2002


Mark,

This patch has a small problem on one path thru the code it is using an unitialised variable
(i.e member) I did a quick grep thru the testsuite and didn't find any C++ testcase which
would trigger the error msg.

> ! }
>   
> ! /* This function is called by the parser to process a class member
> !    access expression of the form OBJECT.NAME.  NAME is a node used by
> !    the parser to represent a name; it is not yet a DECL.  It may,
> !    however, be a BASELINK where the BASELINK_FUNCTIONS is a
> !    TEMPLATE_ID_EXPR.  Templates must be looked up by the parser, and
> !    there is no reason to do the lookup twice, so the parser keeps the
> !    BASELINK.  */
>   
> ! tree
> ! finish_class_member_access_expr (tree object, tree name)
> ! {
> !   tree object_type;
> !   tree member;
> !   tree access_path = NULL_TREE;
>   
> !   if (object == error_mark_node || name == error_mark_node)
> !     return error_mark_node;
>   
> !   if (processing_template_decl)
> !     return build_min_nt (COMPONENT_REF, object, name);
> !   
> !   if (TREE_CODE (object) == OFFSET_REF)
> !     object = resolve_offset_ref (object);
> ! 
> !   object_type = TREE_TYPE (object);
> !   if (TREE_CODE (object_type) == REFERENCE_TYPE)
> !     {
> !       object = convert_from_reference (object);
> !       object_type = TREE_TYPE (object);
>       }
>   
> !   /* [expr.ref]
>   
> !      The type of the first expression shall be "class object" (of a
> !      complete type).  */
> !   if (!complete_type_or_else (object_type, object))
> !     return error_mark_node;
> !   if (!CLASS_TYPE_P (object_type))
> !     {
> !       error ("request for member `%D' in `%E', which is of non-class type `%T'", 
> ! 	     name, object, object_type);
> !       return error_mark_node;
> !     }
>   
> !   if (BASELINK_P (name))
> !     {
> !       /* A member function that has already been looked up.  */
> !       my_friendly_assert ((TREE_CODE (BASELINK_FUNCTIONS (name)) 
> ! 			   == TEMPLATE_ID_EXPR), 
> ! 			  20020805);
> !       member = name;
> !     }
> !   else
> !     {
> !       bool is_template_id = false;
> !       tree template_args = NULL_TREE;
>   
> !       if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
>   	{
> ! 	  is_template_id = true;
> ! 	  template_args = TREE_OPERAND (name, 1);
> ! 	  name = TREE_OPERAND (name, 0);
> ! 	}
> ! 
> !       if (TREE_CODE (name) == SCOPE_REF)
> ! 	{
> ! 	  tree scope;
> ! 
> ! 	  /* A qualified name.  The qualifying class or namespace `S' has
> ! 	     already been looked up; it is either a TYPE or a
> ! 	     NAMESPACE_DECL.  The member name is either an IDENTIFIER_NODE
> ! 	     or a BIT_NOT_EXPR.  */
> ! 	  scope = TREE_OPERAND (name, 0);
> ! 	  name = TREE_OPERAND (name, 1);
> ! 	  my_friendly_assert ((CLASS_TYPE_P (scope) 
> ! 			       || TREE_CODE (scope) == NAMESPACE_DECL),
> ! 			      20020804);
> ! 	  my_friendly_assert ((TREE_CODE (name) == IDENTIFIER_NODE
> ! 			       || TREE_CODE (name) == BIT_NOT_EXPR),
> ! 			      20020804);
> ! 
> ! 	  /* If SCOPE is a namespace, then the qualified name does not
> ! 	     name a member of OBJECT_TYPE.  */
> ! 	  if (TREE_CODE (scope) == NAMESPACE_DECL)
> ! 	    {
> ! 	      error ("`%D::%D' is not a member of `%T'", 
> ! 		     scope, member, object_type);
                             ^^^^^^ member hasn't been initialised.
			    I suspect this should be name?

> ! 	      return error_mark_node;
> ! 	    }

Cheers
Graham



More information about the Gcc-patches mailing list