summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/cp/cvt.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gcc/cp/cvt.c')
-rw-r--r--contrib/gcc/cp/cvt.c159
1 files changed, 67 insertions, 92 deletions
diff --git a/contrib/gcc/cp/cvt.c b/contrib/gcc/cp/cvt.c
index 1603a2a..75a6a3a 100644
--- a/contrib/gcc/cp/cvt.c
+++ b/contrib/gcc/cp/cvt.c
@@ -52,7 +52,7 @@ static void warn_ref_binding PARAMS ((tree, tree, tree));
narrowing is always done with a NOP_EXPR:
In convert.c, convert_to_integer.
In c-typeck.c, build_binary_op_nodefault (boolean ops),
- and truthvalue_conversion.
+ and c_common_truthvalue_conversion.
In expr.c: expand_expr, for operands of a MULT_EXPR.
In fold-const.c: fold.
In tree.c: get_narrower and get_unwidened.
@@ -90,7 +90,7 @@ cp_convert_to_pointer (type, expr, force)
return error_mark_node;
}
- rval = build_type_conversion (type, expr, 1);
+ rval = build_type_conversion (type, expr);
if (rval)
{
if (rval == error_mark_node)
@@ -130,6 +130,9 @@ cp_convert_to_pointer (type, expr, force)
intype = TREE_TYPE (expr);
}
+ if (expr == error_mark_node)
+ return error_mark_node;
+
form = TREE_CODE (intype);
if (POINTER_TYPE_P (intype))
@@ -145,31 +148,33 @@ cp_convert_to_pointer (type, expr, force)
{
enum tree_code code = PLUS_EXPR;
tree binfo;
-
- /* Try derived to base conversion. */
- binfo = lookup_base (TREE_TYPE (intype), TREE_TYPE (type),
- ba_check, NULL);
- if (!binfo)
+ tree intype_class;
+ tree type_class;
+ bool same_p;
+
+ intype_class = TREE_TYPE (intype);
+ type_class = TREE_TYPE (type);
+
+ same_p = same_type_p (TYPE_MAIN_VARIANT (intype_class),
+ TYPE_MAIN_VARIANT (type_class));
+ binfo = NULL_TREE;
+ /* Try derived to base conversion. */
+ if (!same_p)
+ binfo = lookup_base (intype_class, type_class, ba_check, NULL);
+ if (!same_p && !binfo)
{
- /* Try base to derived conversion. */
- binfo = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
- ba_check, NULL);
+ /* Try base to derived conversion. */
+ binfo = lookup_base (type_class, intype_class, ba_check, NULL);
code = MINUS_EXPR;
}
if (binfo == error_mark_node)
return error_mark_node;
- if (binfo)
+ if (binfo || same_p)
{
- expr = build_base_path (code, expr, binfo, 0);
- /* Add any qualifier conversions. */
- if (!same_type_p (TREE_TYPE (TREE_TYPE (expr)),
- TREE_TYPE (type)))
- {
- expr = build1 (NOP_EXPR, type, expr);
- TREE_CONSTANT (expr) =
- TREE_CONSTANT (TREE_OPERAND (expr, 0));
- }
- return expr;
+ if (binfo)
+ expr = build_base_path (code, expr, binfo, 0);
+ /* Add any qualifier conversions. */
+ return build_nop (type, expr);
}
}
@@ -222,9 +227,7 @@ cp_convert_to_pointer (type, expr, force)
return error_mark_node;
}
- rval = build1 (NOP_EXPR, type, expr);
- TREE_CONSTANT (rval) = TREE_CONSTANT (expr);
- return rval;
+ return build_nop (type, expr);
}
else if (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype))
return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0);
@@ -253,12 +256,18 @@ cp_convert_to_pointer (type, expr, force)
force_fit_type (expr, 0);
return expr;
}
+ else if ((TYPE_PTRMEM_P (type) || TYPE_PTRMEMFUNC_P (type))
+ && INTEGRAL_CODE_P (form))
+ {
+ error ("invalid conversion from '%T' to '%T'", intype, type);
+ return error_mark_node;
+ }
if (INTEGRAL_CODE_P (form))
{
if (TYPE_PRECISION (intype) == POINTER_SIZE)
return build1 (CONVERT_EXPR, type, expr);
- expr = cp_convert (type_for_size (POINTER_SIZE, 0), expr);
+ expr = cp_convert (c_common_type_for_size (POINTER_SIZE, 0), expr);
/* Modes may be different but sizes should be the same. */
if (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (expr)))
!= GET_MODE_SIZE (TYPE_MODE (type)))
@@ -313,19 +322,14 @@ convert_to_pointer_force (type, expr)
if (binfo)
{
expr = build_base_path (code, expr, binfo, 0);
- if (expr == error_mark_node)
- return error_mark_node;
- /* Add any qualifier conversions. */
+ if (expr == error_mark_node)
+ return error_mark_node;
+ /* Add any qualifier conversions. */
if (!same_type_p (TREE_TYPE (TREE_TYPE (expr)),
TREE_TYPE (type)))
- {
- expr = build1 (NOP_EXPR, type, expr);
- TREE_CONSTANT (expr) =
- TREE_CONSTANT (TREE_OPERAND (expr, 0));
- }
+ expr = build_nop (type, expr);
return expr;
}
-
}
}
@@ -348,7 +352,6 @@ build_up_reference (type, arg, flags, decl)
tree rval;
tree argtype = TREE_TYPE (arg);
tree target_type = TREE_TYPE (type);
- tree stmt_expr = NULL_TREE;
my_friendly_assert (TREE_CODE (type) == REFERENCE_TYPE, 187);
@@ -358,25 +361,7 @@ build_up_reference (type, arg, flags, decl)
here because it needs to live as long as DECL. */
tree targ = arg;
- arg = build_decl (VAR_DECL, NULL_TREE, argtype);
- DECL_ARTIFICIAL (arg) = 1;
- TREE_USED (arg) = 1;
- TREE_STATIC (arg) = TREE_STATIC (decl);
-
- if (TREE_STATIC (decl))
- {
- /* Namespace-scope or local static; give it a mangled name. */
- tree name = mangle_ref_init_variable (decl);
- DECL_NAME (arg) = name;
- SET_DECL_ASSEMBLER_NAME (arg, name);
- arg = pushdecl_top_level (arg);
- }
- else
- {
- /* Automatic; make sure we handle the cleanup properly. */
- maybe_push_cleanup_level (argtype);
- arg = pushdecl (arg);
- }
+ arg = make_temporary_var_for_ref_to_temp (decl, TREE_TYPE (arg));
/* Process the initializer for the declaration. */
DECL_INITIAL (arg) = targ;
@@ -409,16 +394,7 @@ build_up_reference (type, arg, flags, decl)
else
rval
= convert_to_pointer_force (build_pointer_type (target_type), rval);
- rval = build1 (NOP_EXPR, type, rval);
- TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0));
-
- /* If we created and initialized a new temporary variable, add the
- representation of that initialization to the RVAL. */
- if (stmt_expr)
- rval = build (COMPOUND_EXPR, TREE_TYPE (rval), stmt_expr, rval);
-
- /* And return the result. */
- return rval;
+ return build_nop (type, rval);
}
/* Subroutine of convert_to_reference. REFTYPE is the target reference type.
@@ -500,7 +476,7 @@ convert_to_reference (reftype, expr, convtype, flags, decl)
/* Look for a user-defined conversion to lvalue that we can use. */
rval_as_conversion
- = build_type_conversion (reftype, expr, 1);
+ = build_type_conversion (reftype, expr);
if (rval_as_conversion && rval_as_conversion != error_mark_node
&& real_lvalue_p (rval_as_conversion))
@@ -609,6 +585,21 @@ convert_lvalue (totype, expr)
NULL_TREE);
return convert_from_reference (expr);
}
+
+/* Really perform an lvalue-to-rvalue conversion, including copying an
+ argument of class type into a temporary. */
+
+tree
+force_rvalue (tree expr)
+{
+ if (IS_AGGR_TYPE (TREE_TYPE (expr)) && TREE_CODE (expr) != TARGET_EXPR)
+ expr = ocp_convert (TREE_TYPE (expr), expr,
+ CONV_IMPLICIT|CONV_FORCE_TEMP, LOOKUP_NORMAL);
+ else
+ expr = decay_conversion (expr);
+
+ return expr;
+}
/* C++ conversions, preference to static cast conversions. */
@@ -697,7 +688,7 @@ ocp_convert (type, expr, convtype, flags)
if (IS_AGGR_TYPE (intype))
{
tree rval;
- rval = build_type_conversion (type, e, 1);
+ rval = build_type_conversion (type, e);
if (rval)
return rval;
if (flags & LOOKUP_COMPLAIN)
@@ -733,7 +724,7 @@ ocp_convert (type, expr, convtype, flags)
if (IS_AGGR_TYPE (TREE_TYPE (e)))
{
tree rval;
- rval = build_type_conversion (type, e, 1);
+ rval = build_type_conversion (type, e);
if (rval)
return rval;
else
@@ -776,22 +767,14 @@ ocp_convert (type, expr, convtype, flags)
the target with the temp (see [dcl.init]). */
ctor = build_user_type_conversion (type, ctor, flags);
else
- ctor = build_method_call (NULL_TREE,
- complete_ctor_identifier,
- build_tree_list (NULL_TREE, ctor),
- TYPE_BINFO (type), flags);
+ ctor = build_special_member_call (NULL_TREE,
+ complete_ctor_identifier,
+ build_tree_list (NULL_TREE, ctor),
+ TYPE_BINFO (type), flags);
if (ctor)
return build_cplus_new (type, ctor);
}
- /* If TYPE or TREE_TYPE (E) is not on the permanent_obstack,
- then it won't be hashed and hence compare as not equal,
- even when it is. */
- if (code == ARRAY_TYPE
- && TREE_TYPE (TREE_TYPE (e)) == TREE_TYPE (type)
- && index_type_equal (TYPE_DOMAIN (TREE_TYPE (e)), TYPE_DOMAIN (type)))
- return e;
-
if (flags & LOOKUP_COMPLAIN)
error ("conversion from `%T' to non-scalar type `%T' requested",
TREE_TYPE (expr), type);
@@ -864,7 +847,7 @@ convert_to_void (expr, implicit)
case NON_LVALUE_EXPR:
case NOP_EXPR:
- /* These have already decayed to rvalue. */
+ /* These have already decayed to rvalue. */
break;
case CALL_EXPR: /* we have a special meaning for volatile void fn() */
@@ -1021,26 +1004,18 @@ convert_force (type, expr, convtype)
allowed (references private members, etc).
If no conversion exists, NULL_TREE is returned.
- If (FOR_SURE & 1) is non-zero, then we allow this type conversion
- to take place immediately. Otherwise, we build a SAVE_EXPR
- which can be evaluated if the results are ever needed.
-
- Changes to this functions should be mirrored in user_harshness.
-
FIXME: Ambiguity checking is wrong. Should choose one by the implicit
object parameter, or by the second standard conversion sequence if
that doesn't do it. This will probably wait for an overloading rewrite.
(jason 8/9/95) */
tree
-build_type_conversion (xtype, expr, for_sure)
+build_type_conversion (xtype, expr)
tree xtype, expr;
- int for_sure;
{
/* C++: check to see if we can convert this aggregate type
into the required type. */
- return build_user_type_conversion
- (xtype, expr, for_sure ? LOOKUP_NORMAL : 0);
+ return build_user_type_conversion (xtype, expr, LOOKUP_NORMAL);
}
/* Convert the given EXPR to one of a group of types suitable for use in an
@@ -1186,10 +1161,10 @@ type_promotes_to (type)
{
int precision = MAX (TYPE_PRECISION (type),
TYPE_PRECISION (integer_type_node));
- tree totype = type_for_size (precision, 0);
+ tree totype = c_common_type_for_size (precision, 0);
if (TREE_UNSIGNED (type)
&& ! int_fits_type_p (TYPE_MAX_VALUE (type), totype))
- type = type_for_size (precision, 1);
+ type = c_common_type_for_size (precision, 1);
else
type = totype;
}
OpenPOWER on IntegriCloud