FreeBSD/contrib/gcc/cp/typeck.c
/* Return a tree for the difference of pointers OP0 and OP1.
   The resulting tree has type int.  */
Return a tree for the difference of pointers OP0 and OP1.
The resulting tree has type int.
Return a tree for the difference of pointers OP0 and OP1 . The resulting tree has type int .
static tree
pointer_diff (tree op0, tree op1, tree ptrtype)
{
  tree result;
  tree restype = ptrdiff_type_node;
  tree target_type = TREE_TYPE (ptrtype);
  if (!complete_type_or_else (target_type, NULL_TREE))
    return error_mark_node;
  if (pedantic || warn_pointer_arith)
    {
      if (TREE_CODE (target_type) == VOID_TYPE)
	pedwarn ("ISO C++ forbids using pointer of type %<void *%> in subtraction");
      if (TREE_CODE (target_type) == FUNCTION_TYPE)
	pedwarn ("ISO C++ forbids using pointer to a function in subtraction");
      if (TREE_CODE (target_type) == METHOD_TYPE)
	pedwarn ("ISO C++ forbids using pointer to a method in subtraction");
    }
  op0 = cp_build_binary_op (MINUS_EXPR,
			    cp_convert (restype, op0),
			    cp_convert (restype, op1));
  if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (op1))))
    error ("invalid use of a pointer to an incomplete type in pointer arithmetic");
  op1 = (TYPE_PTROB_P (ptrtype)
	 ? size_in_bytes (target_type)
	 : integer_one_node);
  result = build2 (EXACT_DIV_EXPR, restype, op0, cp_convert (restype, op1));
  return fold_if_not_in_template (result);
}
static tree pointer_diff ( tree op0 , tree op1 , tree ptrtype ) { tree result ; tree restype = ptrdiff_type_node ; tree target_type = TREE_TYPE ( ptrtype ) ; if ( ! complete_type_or_else ( target_type , NULL_TREE ) ) return error_mark_node ; if ( pedantic || warn_pointer_arith ) { if ( TREE_CODE ( target_type ) == VOID_TYPE ) pedwarn ( " " ) ; if ( TREE_CODE ( target_type ) == FUNCTION_TYPE ) pedwarn ( " " ) ; if ( TREE_CODE ( target_type ) == METHOD_TYPE ) pedwarn ( " " ) ; } op0 = cp_build_binary_op ( MINUS_EXPR , cp_convert ( restype , op0 ) , cp_convert ( restype , op1 ) ) ; if ( ! COMPLETE_TYPE_P ( TREE_TYPE ( TREE_TYPE ( op1 ) ) ) ) error ( " " ) ; op1 = ( TYPE_PTROB_P ( ptrtype ) ? size_in_bytes ( target_type ) : integer_one_node ) ; result = build2 ( EXACT_DIV_EXPR , restype , op0 , cp_convert ( restype , op1 ) ) ; return fold_if_not_in_template ( result ) ; }
Return a tree for the difference of pointers OP0 and OP1.
Return a tree for the difference of pointers OP0 and OP1 .
/* First do the subtraction as integers;
     then drop through to build the divide operator.  */ /* This generates an error if op1 is a pointer to an incomplete type.  */ /* Do the division.  */