Commit bf31620c by Jason Merrill Committed by Jason Merrill

Don't fold conversion from a constant variable.

	* call.c (convert_like_real): Remove "inner" parameter.
	Don't replace a constant with its value.
	* cp-gimplify.c (cp_fully_fold): Use cp_fold_rvalue.

From-SVN: r249083
parent b09649fd
2017-06-09 Jason Merrill <jason@redhat.com> 2017-06-09 Jason Merrill <jason@redhat.com>
* call.c (convert_like_real): Remove "inner" parameter.
Don't replace a constant with its value.
* cp-gimplify.c (cp_fully_fold): Use cp_fold_rvalue.
* pt.c (convert_nontype_argument): Check NULLPTR_TYPE_P rather than * pt.c (convert_nontype_argument): Check NULLPTR_TYPE_P rather than
nullptr_node. nullptr_node.
......
...@@ -147,14 +147,14 @@ static int joust (struct z_candidate *, struct z_candidate *, bool, ...@@ -147,14 +147,14 @@ static int joust (struct z_candidate *, struct z_candidate *, bool,
static int compare_ics (conversion *, conversion *); static int compare_ics (conversion *, conversion *);
static tree build_over_call (struct z_candidate *, int, tsubst_flags_t); static tree build_over_call (struct z_candidate *, int, tsubst_flags_t);
#define convert_like(CONV, EXPR, COMPLAIN) \ #define convert_like(CONV, EXPR, COMPLAIN) \
convert_like_real ((CONV), (EXPR), NULL_TREE, 0, 0, \ convert_like_real ((CONV), (EXPR), NULL_TREE, 0, \
/*issue_conversion_warnings=*/true, \ /*issue_conversion_warnings=*/true, \
/*c_cast_p=*/false, (COMPLAIN)) /*c_cast_p=*/false, (COMPLAIN))
#define convert_like_with_context(CONV, EXPR, FN, ARGNO, COMPLAIN ) \ #define convert_like_with_context(CONV, EXPR, FN, ARGNO, COMPLAIN ) \
convert_like_real ((CONV), (EXPR), (FN), (ARGNO), 0, \ convert_like_real ((CONV), (EXPR), (FN), (ARGNO), \
/*issue_conversion_warnings=*/true, \ /*issue_conversion_warnings=*/true, \
/*c_cast_p=*/false, (COMPLAIN)) /*c_cast_p=*/false, (COMPLAIN))
static tree convert_like_real (conversion *, tree, tree, int, int, bool, static tree convert_like_real (conversion *, tree, tree, int, bool,
bool, tsubst_flags_t); bool, tsubst_flags_t);
static void op_error (location_t, enum tree_code, enum tree_code, tree, static void op_error (location_t, enum tree_code, enum tree_code, tree,
tree, tree, bool); tree, tree, bool);
...@@ -6552,7 +6552,7 @@ maybe_print_user_conv_context (conversion *convs) ...@@ -6552,7 +6552,7 @@ maybe_print_user_conv_context (conversion *convs)
static tree static tree
convert_like_real (conversion *convs, tree expr, tree fn, int argnum, convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
int inner, bool issue_conversion_warnings, bool issue_conversion_warnings,
bool c_cast_p, tsubst_flags_t complain) bool c_cast_p, tsubst_flags_t complain)
{ {
tree totype = convs->type; tree totype = convs->type;
...@@ -6606,7 +6606,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6606,7 +6606,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
totype); totype);
if (complained) if (complained)
print_z_candidate (loc, "candidate is:", t->cand); print_z_candidate (loc, "candidate is:", t->cand);
expr = convert_like_real (t, expr, fn, argnum, 1, expr = convert_like_real (t, expr, fn, argnum,
/*issue_conversion_warnings=*/false, /*issue_conversion_warnings=*/false,
/*c_cast_p=*/false, /*c_cast_p=*/false,
complain); complain);
...@@ -6623,14 +6623,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6623,14 +6623,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
} }
else if (t->kind == ck_user || !t->bad_p) else if (t->kind == ck_user || !t->bad_p)
{ {
expr = convert_like_real (t, expr, fn, argnum, 1, expr = convert_like_real (t, expr, fn, argnum,
/*issue_conversion_warnings=*/false, /*issue_conversion_warnings=*/false,
/*c_cast_p=*/false, /*c_cast_p=*/false,
complain); complain);
break; break;
} }
else if (t->kind == ck_ambig) else if (t->kind == ck_ambig)
return convert_like_real (t, expr, fn, argnum, 1, return convert_like_real (t, expr, fn, argnum,
/*issue_conversion_warnings=*/false, /*issue_conversion_warnings=*/false,
/*c_cast_p=*/false, /*c_cast_p=*/false,
complain); complain);
...@@ -6734,18 +6734,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6734,18 +6734,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
if (type_unknown_p (expr)) if (type_unknown_p (expr))
expr = instantiate_type (totype, expr, complain); expr = instantiate_type (totype, expr, complain);
/* Convert a constant to its underlying value, unless we are
about to bind it to a reference, in which case we need to
leave it as an lvalue. */
if (inner >= 0)
{
expr = scalar_constant_value (expr);
if (expr == null_node && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (totype))
/* If __null has been converted to an integer type, we do not
want to warn about uses of EXPR as an integer, rather than
as a pointer. */
expr = build_int_cst (totype, 0);
}
return expr; return expr;
case ck_ambig: case ck_ambig:
/* We leave bad_p off ck_ambig because overload resolution considers /* We leave bad_p off ck_ambig because overload resolution considers
...@@ -6776,7 +6764,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6776,7 +6764,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val) FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val)
{ {
tree sub = convert_like_real (convs->u.list[ix], val, fn, argnum, tree sub = convert_like_real (convs->u.list[ix], val, fn, argnum,
1, false, false, complain); false, false, complain);
if (sub == error_mark_node) if (sub == error_mark_node)
return sub; return sub;
if (!BRACE_ENCLOSED_INITIALIZER_P (val) if (!BRACE_ENCLOSED_INITIALIZER_P (val)
...@@ -6832,7 +6820,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6832,7 +6820,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
}; };
expr = convert_like_real (next_conversion (convs), expr, fn, argnum, expr = convert_like_real (next_conversion (convs), expr, fn, argnum,
convs->kind == ck_ref_bind ? -1 : 1,
convs->kind == ck_ref_bind ? issue_conversion_warnings : false, convs->kind == ck_ref_bind ? issue_conversion_warnings : false,
c_cast_p, c_cast_p,
complain); complain);
...@@ -10173,7 +10160,7 @@ perform_direct_initialization_if_possible (tree type, ...@@ -10173,7 +10160,7 @@ perform_direct_initialization_if_possible (tree type,
if (!conv || conv->bad_p) if (!conv || conv->bad_p)
expr = NULL_TREE; expr = NULL_TREE;
else else
expr = convert_like_real (conv, expr, NULL_TREE, 0, 0, expr = convert_like_real (conv, expr, NULL_TREE, 0,
/*issue_conversion_warnings=*/false, /*issue_conversion_warnings=*/false,
c_cast_p, c_cast_p,
complain); complain);
......
...@@ -1935,20 +1935,6 @@ cxx_omp_disregard_value_expr (tree decl, bool shared) ...@@ -1935,20 +1935,6 @@ cxx_omp_disregard_value_expr (tree decl, bool shared)
&& DECL_OMP_PRIVATIZED_MEMBER (decl); && DECL_OMP_PRIVATIZED_MEMBER (decl);
} }
/* Perform folding on expression X. */
tree
cp_fully_fold (tree x)
{
if (processing_template_decl)
return x;
/* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't
have to call both. */
if (cxx_dialect >= cxx11)
x = maybe_constant_value (x);
return cp_fold (x);
}
/* Fold expression X which is used as an rvalue if RVAL is true. */ /* Fold expression X which is used as an rvalue if RVAL is true. */
static tree static tree
...@@ -1980,6 +1966,20 @@ cp_fold_rvalue (tree x) ...@@ -1980,6 +1966,20 @@ cp_fold_rvalue (tree x)
return cp_fold_maybe_rvalue (x, true); return cp_fold_maybe_rvalue (x, true);
} }
/* Perform folding on expression X. */
tree
cp_fully_fold (tree x)
{
if (processing_template_decl)
return x;
/* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't
have to call both. */
if (cxx_dialect >= cxx11)
x = maybe_constant_value (x);
return cp_fold_rvalue (x);
}
/* c-common interface to cp_fold. If IN_INIT, this is in a static initializer /* c-common interface to cp_fold. If IN_INIT, this is in a static initializer
and certain changes are made to the folding done. Or should be (FIXME). We and certain changes are made to the folding done. Or should be (FIXME). We
never touch maybe_const, as it is only used for the C front-end never touch maybe_const, as it is only used for the C front-end
......
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