On Thu, Mar 10, 2016 at 01:46:45PM +0100, Marek Polacek wrote:
> 2016-03-10 Marek Polacek <[email protected]>
>
> PR c++/70153
> * cp-gimplify.c (cp_fold): Handle UNARY_PLUS_EXPR.
>
> * g++.dg/delayedfold/unary-plus1.C: New test.
>
> diff --git gcc/cp/cp-gimplify.c gcc/cp/cp-gimplify.c
> index 6af3760..db23efe 100644
> --- gcc/cp/cp-gimplify.c
> +++ gcc/cp/cp-gimplify.c
> @@ -2009,6 +2009,8 @@ cp_fold (tree x)
> else
> x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
> }
> + else if (code == UNARY_PLUS_EXPR)
> + x = fold_convert (TREE_TYPE (x), op0);
> else
> x = fold (x);
>
Won't this still leak UNARY_PLUS_EXPR into the folded result if
you could fold the operand of that? It will take the
x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
path...
Wouldn't it be better to just handle case UNARY_PLUS_EXPR:
separately, and always optimize it away?
So like:
case UNARY_PLUS_EXPR:
loc = EXPR_LOCATION (x);
op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops);
if (op0 == error_mark_node)
x = error_mark_node;
else
x = fold_convert_loc (loc, TREE_TYPE (x), op0);
break;
or so?
Jakub