FreeBSD/contrib/gcc/cp/typeck.c
/* If two types share a common base type, return that basetype.
   If there is not a unique most-derived base type, this function
   returns ERROR_MARK_NODE.  */
If two types share a common base type, return that basetype.
If there is not a unique most-derived base type, this function
returns ERROR_MARK_NODE.
If two types share a common base type return that basetype . If there is not a unique most - derived base type this function returns ERROR_MARK_NODE .
static tree
common_base_type (tree tt1, tree tt2)
{
  tree best = NULL_TREE;
  int i;
  if (UNIQUELY_DERIVED_FROM_P (tt1, tt2))
    return tt1;
  if (UNIQUELY_DERIVED_FROM_P (tt2, tt1))
    return tt2;
  for (i = BINFO_N_BASE_BINFOS (TYPE_BINFO (tt1))-1; i >= 0; i--)
    {
      tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (tt1), i));
      tree trial = common_base_type (basetype, tt2);
      if (trial)
	{
	  if (trial == error_mark_node)
	    return trial;
	  if (best == NULL_TREE)
	    best = trial;
	  else if (best != trial)
	    return error_mark_node;
	}
    }
  for (i = BINFO_N_BASE_BINFOS (TYPE_BINFO (tt2))-1; i >= 0; i--)
    {
      tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (tt2), i));
      tree trial = common_base_type (tt1, basetype);
      if (trial)
	{
	  if (trial == error_mark_node)
	    return trial;
	  if (best == NULL_TREE)
	    best = trial;
	  else if (best != trial)
	    return error_mark_node;
	}
    }
  return best;
}
static tree common_base_type ( tree tt1 , tree tt2 ) { tree best = NULL_TREE ; int i ; if ( UNIQUELY_DERIVED_FROM_P ( tt1 , tt2 ) ) return tt1 ; if ( UNIQUELY_DERIVED_FROM_P ( tt2 , tt1 ) ) return tt2 ; for ( i = BINFO_N_BASE_BINFOS ( TYPE_BINFO ( tt1 ) ) - 1 ; i >= 0 ; i -- ) { tree basetype = BINFO_TYPE ( BINFO_BASE_BINFO ( TYPE_BINFO ( tt1 ) , i ) ) ; tree trial = common_base_type ( basetype , tt2 ) ; if ( trial ) { if ( trial == error_mark_node ) return trial ; if ( best == NULL_TREE ) best = trial ; else if ( best != trial ) return error_mark_node ; } } for ( i = BINFO_N_BASE_BINFOS ( TYPE_BINFO ( tt2 ) ) - 1 ; i >= 0 ; i -- ) { tree basetype = BINFO_TYPE ( BINFO_BASE_BINFO ( TYPE_BINFO ( tt2 ) , i ) ) ; tree trial = common_base_type ( tt1 , basetype ) ; if ( trial ) { if ( trial == error_mark_node ) return trial ; if ( best == NULL_TREE ) best = trial ; else if ( best != trial ) return error_mark_node ; } } return best ; }
If two types share a common base type, return that basetype.
If two types share a common base type return that basetype .
/* If one is a baseclass of another, that's good enough.  */ /* Otherwise, try to find a unique baseclass of TT1
     that is shared by TT2, and follow that down.  */ /* Same for TT2.  */