FreeBSD/contrib/gcc/cp/typeck.c
/* Build an expression representing an explicit C-style cast to type
   TYPE of expression EXPR.  */
Build an expression representing an explicit C-style cast to type
TYPE of expression EXPR.
Build an expression representing an explicit C - style cast to type TYPE of expression EXPR .
tree
build_c_cast (tree type, tree expr)
{
  tree value = expr;
  tree result;
  bool valid_p;
  if (type == error_mark_node || error_operand_p (expr))
    return error_mark_node;
  if (processing_template_decl)
    {
      tree t = build_min (CAST_EXPR, type,
			  tree_cons (NULL_TREE, value, NULL_TREE));
      TREE_SIDE_EFFECTS (t) = 1;
      return convert_from_reference (t);
    }
  if (objc_is_object_ptr (type)
      && objc_is_object_ptr (TREE_TYPE (expr)))
    return build_nop (type, expr);
  if (TREE_CODE (type) != REFERENCE_TYPE
      && TREE_CODE (value) == NOP_EXPR
      && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
    value = TREE_OPERAND (value, 0);
  if (TREE_CODE (type) == ARRAY_TYPE)
    {
      if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)
	{
	  pedwarn ("ISO C++ forbids casting to an array type %qT", type);
	  type = build_pointer_type (TREE_TYPE (type));
	}
      else
	{
	  error ("ISO C++ forbids casting to an array type %qT", type);
	  return error_mark_node;
	}
    }
  if (TREE_CODE (type) == FUNCTION_TYPE
      || TREE_CODE (type) == METHOD_TYPE)
    {
      error ("invalid cast to function type %qT", type);
      return error_mark_node;
    }
  result = build_const_cast_1 (type, value, false,
			       &valid_p);
  if (valid_p)
    return result;
  result = build_static_cast_1 (type, value, true,
				&valid_p);
  if (!valid_p)
    result = build_reinterpret_cast_1 (type, value, true,
				       &valid_p);
  if (valid_p
      && !error_operand_p (result))
    {
      tree result_type;
      if (!CLASS_TYPE_P (type))
	type = TYPE_MAIN_VARIANT (type);
      result_type = TREE_TYPE (result);
      if (!CLASS_TYPE_P (result_type))
	result_type = TYPE_MAIN_VARIANT (result_type);
      if (!same_type_p (non_reference (type), non_reference (result_type)))
	{
	  result = build_const_cast_1 (type, result, false, &valid_p);
	  gcc_assert (valid_p);
	}
      return result;
    }
  return error_mark_node;
}
tree build_c_cast ( tree type , tree expr ) { tree value = expr ; tree result ; bool valid_p ; if ( type == error_mark_node || error_operand_p ( expr ) ) return error_mark_node ; if ( processing_template_decl ) { tree t = build_min ( CAST_EXPR , type , tree_cons ( NULL_TREE , value , NULL_TREE ) ) ; TREE_SIDE_EFFECTS ( t ) = 1 ; return convert_from_reference ( t ) ; } if ( objc_is_object_ptr ( type ) && objc_is_object_ptr ( TREE_TYPE ( expr ) ) ) return build_nop ( type , expr ) ; if ( TREE_CODE ( type ) != REFERENCE_TYPE && TREE_CODE ( value ) == NOP_EXPR && TREE_TYPE ( value ) == TREE_TYPE ( TREE_OPERAND ( value , 0 ) ) ) value = TREE_OPERAND ( value , 0 ) ; if ( TREE_CODE ( type ) == ARRAY_TYPE ) { if ( TREE_CODE ( TREE_TYPE ( expr ) ) == POINTER_TYPE ) { pedwarn ( " " , type ) ; type = build_pointer_type ( TREE_TYPE ( type ) ) ; } else { error ( " " , type ) ; return error_mark_node ; } } if ( TREE_CODE ( type ) == FUNCTION_TYPE || TREE_CODE ( type ) == METHOD_TYPE ) { error ( " " , type ) ; return error_mark_node ; } result = build_const_cast_1 ( type , value , false , & valid_p ) ; if ( valid_p ) return result ; result = build_static_cast_1 ( type , value , true , & valid_p ) ; if ( ! valid_p ) result = build_reinterpret_cast_1 ( type , value , true , & valid_p ) ; if ( valid_p && ! error_operand_p ( result ) ) { tree result_type ; if ( ! CLASS_TYPE_P ( type ) ) type = TYPE_MAIN_VARIANT ( type ) ; result_type = TREE_TYPE ( result ) ; if ( ! CLASS_TYPE_P ( result_type ) ) result_type = TYPE_MAIN_VARIANT ( result_type ) ; if ( ! same_type_p ( non_reference ( type ) , non_reference ( result_type ) ) ) { result = build_const_cast_1 ( type , result , false , & valid_p ) ; gcc_assert ( valid_p ) ; } return result ; } return error_mark_node ; }
Build an expression representing an explicit C-style cast to type
TYPE of expression EXPR.
Build an expression representing an explicit C - style cast to type TYPE of expression EXPR .
/* We don't know if it will or will not have side effects.  */ /* Casts to a (pointer to a) specific ObjC class (or 'id' or
     'Class') should always be retained, because this information aids
     in method lookup.  */ /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
     Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */ /* Allow casting from T1* to T2[] because Cfront allows it.
	 NIHCL uses it. It is not valid ISO C++ however.  */ /* A C-style cast can be a const_cast.  */ /*complain=*/ /* Or a static cast.  */ /*c_cast_p=*/ /* Or a reinterpret_cast.  */ /*c_cast_p=*/ /* The static_cast or reinterpret_cast may be followed by a
     const_cast.  */ /* A valid cast may result in errors if, for example, a
	 conversion to am ambiguous base class is required.  */ /* Non-class rvalues always have cv-unqualified type.  */ /* If the type of RESULT does not match TYPE, perform a
	 const_cast to make it match.  If the static_cast or
	 reinterpret_cast succeeded, we will differ by at most
	 cv-qualification, so the follow-on const_cast is guaranteed
	 to succeed.  */