Commit a359be75 by Jason Merrill Committed by Jason Merrill

init.c (resolve_offset_ref): Don't return a raw method.

	* init.c (resolve_offset_ref): Don't return a raw method.
	Use BASELINK_P.
	* typeck.c (decay_conversion): Don't handle a raw method.
	Resolve all OFFSET_REFs.
	(get_member_function_from_ptrfunc): 0 is a valid vtable index.
	(build_binary_op_nodefault): Handle resolving overloaded fns.  Use
	same_type_p for pmf bits.  Don't use build_binary_op to compare
	raw pointers to methods.
	(convert_for_assignment): Check for OFFSET_REF, not OFFSET_TYPE,
	to decide when to call resolve_offset_ref.
	(build_c_cast, convert_for_initialization): Likewise.
	* cvt.c (build_expr_type_conversion): Likewise.

From-SVN: r26815
parent 475836b1
1999-05-07 Jason Merrill <jason@yorick.cygnus.com>
* init.c (resolve_offset_ref): Don't return a raw method.
Use BASELINK_P.
* typeck.c (decay_conversion): Don't handle a raw method.
Resolve all OFFSET_REFs.
(get_member_function_from_ptrfunc): 0 is a valid vtable index.
(build_binary_op_nodefault): Handle resolving overloaded fns. Use
same_type_p for pmf bits. Don't use build_binary_op to compare
raw pointers to methods.
(convert_for_assignment): Check for OFFSET_REF, not OFFSET_TYPE,
to decide when to call resolve_offset_ref.
(build_c_cast, convert_for_initialization): Likewise.
* cvt.c (build_expr_type_conversion): Likewise.
1999-05-06 Nathan Sidwell <nathan@acm.org> 1999-05-06 Nathan Sidwell <nathan@acm.org>
* call.c (build_new_method_call): Use TYPE_MAIN_VARIANT of class. * call.c (build_new_method_call): Use TYPE_MAIN_VARIANT of class.
......
...@@ -976,7 +976,7 @@ build_expr_type_conversion (desires, expr, complain) ...@@ -976,7 +976,7 @@ build_expr_type_conversion (desires, expr, complain)
&& !(desires & WANT_NULL)) && !(desires & WANT_NULL))
cp_warning ("converting NULL to non-pointer type"); cp_warning ("converting NULL to non-pointer type");
if (TREE_CODE (basetype) == OFFSET_TYPE) if (TREE_CODE (expr) == OFFSET_REF || BASELINK_P (expr))
expr = resolve_offset_ref (expr); expr = resolve_offset_ref (expr);
expr = convert_from_reference (expr); expr = convert_from_reference (expr);
basetype = TREE_TYPE (expr); basetype = TREE_TYPE (expr);
......
...@@ -1692,7 +1692,7 @@ resolve_offset_ref (exp) ...@@ -1692,7 +1692,7 @@ resolve_offset_ref (exp)
tree member; tree member;
tree basetype, addr; tree basetype, addr;
if (TREE_CODE (exp) == TREE_LIST) if (BASELINK_P (exp))
{ {
cp_pedwarn ("assuming & on overloaded member function"); cp_pedwarn ("assuming & on overloaded member function");
return build_unary_op (ADDR_EXPR, exp, 0); return build_unary_op (ADDR_EXPR, exp, 0);
...@@ -1719,8 +1719,7 @@ resolve_offset_ref (exp) ...@@ -1719,8 +1719,7 @@ resolve_offset_ref (exp)
if ((TREE_CODE (member) == VAR_DECL if ((TREE_CODE (member) == VAR_DECL
&& ! TYPE_PTRMEMFUNC_P (TREE_TYPE (member)) && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (member))
&& ! TYPE_PTRMEM_P (TREE_TYPE (member))) && ! TYPE_PTRMEM_P (TREE_TYPE (member)))
|| TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE || TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE)
|| TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE)
{ {
/* These were static members. */ /* These were static members. */
if (mark_addressable (member) == 0) if (mark_addressable (member) == 0)
...@@ -1728,6 +1727,12 @@ resolve_offset_ref (exp) ...@@ -1728,6 +1727,12 @@ resolve_offset_ref (exp)
return member; return member;
} }
if (TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE)
{
cp_pedwarn ("assuming & on `%E'", member);
return build_unary_op (ADDR_EXPR, exp, 0);
}
if (TREE_CODE (TREE_TYPE (member)) == POINTER_TYPE if (TREE_CODE (TREE_TYPE (member)) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (TREE_TYPE (member))) == METHOD_TYPE) && TREE_CODE (TREE_TYPE (TREE_TYPE (member))) == METHOD_TYPE)
return member; return member;
......
...@@ -1714,23 +1714,14 @@ tree ...@@ -1714,23 +1714,14 @@ tree
decay_conversion (exp) decay_conversion (exp)
tree exp; tree exp;
{ {
register tree type = TREE_TYPE (exp); register tree type;
register enum tree_code code = TREE_CODE (type); register enum tree_code code;
if (code == OFFSET_TYPE) if (TREE_CODE (exp) == OFFSET_REF || BASELINK_P (exp))
{ exp = resolve_offset_ref (exp);
if (TREE_CODE (exp) == OFFSET_REF)
return decay_conversion (resolve_offset_ref (exp));
type = TREE_TYPE (type); type = TREE_TYPE (exp);
code = TREE_CODE (type); code = TREE_CODE (type);
if (type == unknown_type_node)
{
cp_pedwarn ("assuming & on overloaded member function");
return build_unary_op (ADDR_EXPR, exp, 0);
}
}
if (code == REFERENCE_TYPE) if (code == REFERENCE_TYPE)
{ {
...@@ -1765,10 +1756,7 @@ decay_conversion (exp) ...@@ -1765,10 +1756,7 @@ decay_conversion (exp)
return error_mark_node; return error_mark_node;
} }
if (code == METHOD_TYPE) if (code == METHOD_TYPE)
{ my_friendly_abort (990506);
cp_pedwarn ("assuming & on `%E'", exp);
return build_unary_op (ADDR_EXPR, exp, 0);
}
if (code == FUNCTION_TYPE || is_overloaded_fn (exp)) if (code == FUNCTION_TYPE || is_overloaded_fn (exp))
return build_unary_op (ADDR_EXPR, exp, 0); return build_unary_op (ADDR_EXPR, exp, 0);
if (code == ARRAY_TYPE) if (code == ARRAY_TYPE)
...@@ -2871,7 +2859,7 @@ get_member_function_from_ptrfunc (instance_ptrptr, function) ...@@ -2871,7 +2859,7 @@ get_member_function_from_ptrfunc (instance_ptrptr, function)
(build_component_ref (function, (build_component_ref (function,
index_identifier, index_identifier,
NULL_TREE, 0))); NULL_TREE, 0)));
e1 = build_binary_op (GT_EXPR, idx, integer_zero_node); e1 = build_binary_op (GE_EXPR, idx, integer_zero_node);
/* Convert down to the right base, before using the instance. */ /* Convert down to the right base, before using the instance. */
instance = convert_pointer_to_real (basetype, instance_ptr); instance = convert_pointer_to_real (basetype, instance_ptr);
...@@ -3356,6 +3344,32 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code) ...@@ -3356,6 +3344,32 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
op1 = default_conversion (orig_op1); op1 = default_conversion (orig_op1);
} }
/* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
STRIP_TYPE_NOPS (op0);
STRIP_TYPE_NOPS (op1);
/* DTRT if one side is an overloaded function, but complain about it. */
if (type_unknown_p (op0))
{
tree t = instantiate_type (TREE_TYPE (op1), op0, 0);
if (t != error_mark_node)
{
cp_pedwarn ("assuming cast to `%T' from overloaded function",
TREE_TYPE (t));
op0 = t;
}
}
if (type_unknown_p (op1))
{
tree t = instantiate_type (TREE_TYPE (op0), op1, 0);
if (t != error_mark_node)
{
cp_pedwarn ("assuming cast to `%T' from overloaded function",
TREE_TYPE (t));
op1 = t;
}
}
type0 = TREE_TYPE (op0); type0 = TREE_TYPE (op0);
type1 = TREE_TYPE (op1); type1 = TREE_TYPE (op1);
...@@ -3364,10 +3378,6 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code) ...@@ -3364,10 +3378,6 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
code0 = TREE_CODE (type0); code0 = TREE_CODE (type0);
code1 = TREE_CODE (type1); code1 = TREE_CODE (type1);
/* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
STRIP_TYPE_NOPS (op0);
STRIP_TYPE_NOPS (op1);
/* If an error was already reported for one of the arguments, /* If an error was already reported for one of the arguments,
avoid reporting another error. */ avoid reporting another error. */
...@@ -3640,8 +3650,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code) ...@@ -3640,8 +3650,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
result_type = TREE_TYPE (op0); result_type = TREE_TYPE (op0);
} }
else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1) else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
&& (TYPE_PTRMEMFUNC_FN_TYPE (type0) && same_type_p (type0, type1))
== TYPE_PTRMEMFUNC_FN_TYPE (type1)))
{ {
/* The code we generate for the test is: /* The code we generate for the test is:
...@@ -3665,7 +3674,9 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code) ...@@ -3665,7 +3674,9 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node); e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node);
e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2,
build_binary_op (EQ_EXPR, delta20, delta21)); build_binary_op (EQ_EXPR, delta20, delta21));
e3 = build_binary_op (EQ_EXPR, pfn0, pfn1); /* We can't use build_binary_op for this cmp because it would get
confused by the ptr to method types and think we want pmfs. */
e3 = build (EQ_EXPR, boolean_type_node, pfn0, pfn1);
e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3); e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3);
e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2); e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2);
if (code == EQ_EXPR) if (code == EQ_EXPR)
...@@ -3673,7 +3684,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code) ...@@ -3673,7 +3684,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
return build_binary_op (EQ_EXPR, e2, integer_zero_node); return build_binary_op (EQ_EXPR, e2, integer_zero_node);
} }
else if (TYPE_PTRMEMFUNC_P (type0) else if (TYPE_PTRMEMFUNC_P (type0)
&& TYPE_PTRMEMFUNC_FN_TYPE (type0) == type1) && same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type0), type1))
{ {
tree index0 = build_component_ref (op0, index_identifier, tree index0 = build_component_ref (op0, index_identifier,
NULL_TREE, 0); NULL_TREE, 0);
...@@ -3712,7 +3723,9 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code) ...@@ -3712,7 +3723,9 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node); e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node);
e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2,
build_binary_op (EQ_EXPR, delta20, delta21)); build_binary_op (EQ_EXPR, delta20, delta21));
e3 = build_binary_op (EQ_EXPR, pfn0, op1); /* We can't use build_binary_op for this cmp because it would get
confused by the ptr to method types and think we want pmfs. */
e3 = build (EQ_EXPR, boolean_type_node, pfn0, op1);
e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3); e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3);
e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2); e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2);
if (code == EQ_EXPR) if (code == EQ_EXPR)
...@@ -3720,7 +3733,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code) ...@@ -3720,7 +3733,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
return build_binary_op (EQ_EXPR, e2, integer_zero_node); return build_binary_op (EQ_EXPR, e2, integer_zero_node);
} }
else if (TYPE_PTRMEMFUNC_P (type1) else if (TYPE_PTRMEMFUNC_P (type1)
&& TYPE_PTRMEMFUNC_FN_TYPE (type1) == type0) && same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type1), type0))
return build_binary_op (code, op1, op0); return build_binary_op (code, op1, op0);
break; break;
...@@ -5718,9 +5731,7 @@ build_c_cast (type, expr) ...@@ -5718,9 +5731,7 @@ build_c_cast (type, expr)
&& TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0))) && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
value = TREE_OPERAND (value, 0); value = TREE_OPERAND (value, 0);
if (TREE_TYPE (expr) if (TREE_CODE (value) == OFFSET_REF || BASELINK_P (value))
&& TREE_CODE (TREE_TYPE (expr)) == OFFSET_TYPE
&& TREE_CODE (type) != OFFSET_TYPE)
value = resolve_offset_ref (value); value = resolve_offset_ref (value);
if (TREE_CODE (type) == ARRAY_TYPE) if (TREE_CODE (type) == ARRAY_TYPE)
...@@ -6687,40 +6698,23 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum) ...@@ -6687,40 +6698,23 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
{ {
register enum tree_code codel = TREE_CODE (type); register enum tree_code codel = TREE_CODE (type);
register tree rhstype; register tree rhstype;
register enum tree_code coder = TREE_CODE (TREE_TYPE (rhs)); register enum tree_code coder;
/* Issue warnings about peculiar, but legal, uses of NULL. */
if (ARITHMETIC_TYPE_P (type) && rhs == null_node)
cp_warning ("converting NULL to non-pointer type");
if (coder == ERROR_MARK)
return error_mark_node;
if (codel == OFFSET_TYPE) if (codel == OFFSET_TYPE)
{ my_friendly_abort (990505);
type = TREE_TYPE (type);
codel = TREE_CODE (type); if (TREE_CODE (rhs) == OFFSET_REF || BASELINK_P (rhs))
} rhs = resolve_offset_ref (rhs);
/* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
if (TREE_CODE (rhs) == NON_LVALUE_EXPR) if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
rhs = TREE_OPERAND (rhs, 0); rhs = TREE_OPERAND (rhs, 0);
if (rhs == error_mark_node) if (rhs == error_mark_node || TREE_TYPE (rhs) == error_mark_node)
return error_mark_node; return error_mark_node;
if (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node) if (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)
return error_mark_node; return error_mark_node;
if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
{
rhs = resolve_offset_ref (rhs);
if (rhs == error_mark_node)
return error_mark_node;
rhstype = TREE_TYPE (rhs);
coder = TREE_CODE (rhstype);
}
if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
|| is_overloaded_fn (rhs)) || is_overloaded_fn (rhs))
rhs = default_conversion (rhs); rhs = default_conversion (rhs);
...@@ -6736,6 +6730,10 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum) ...@@ -6736,6 +6730,10 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
rhstype = TREE_TYPE (rhs); rhstype = TREE_TYPE (rhs);
coder = TREE_CODE (rhstype); coder = TREE_CODE (rhstype);
/* Issue warnings about peculiar, but legal, uses of NULL. */
if (ARITHMETIC_TYPE_P (type) && rhs == null_node)
cp_warning ("converting NULL to non-pointer type");
/* This should no longer change types on us. */ /* This should no longer change types on us. */
if (TREE_CODE (rhs) == CONST_DECL) if (TREE_CODE (rhs) == CONST_DECL)
rhs = DECL_INITIAL (rhs); rhs = DECL_INITIAL (rhs);
...@@ -7135,7 +7133,7 @@ convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum) ...@@ -7135,7 +7133,7 @@ convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
|| (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)) || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
return error_mark_node; return error_mark_node;
if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE) if (TREE_CODE (rhs) == OFFSET_REF || BASELINK_P (rhs))
{ {
rhs = resolve_offset_ref (rhs); rhs = resolve_offset_ref (rhs);
if (rhs == error_mark_node) if (rhs == error_mark_node)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment