* cp-tree.def (UNARY_PLUS_EXPR): New C++ unary tree code.
* parser.c (cp_parser_unary_expression): Use UNARY_PLUS_EXPR instead
of CONVERT_EXPR.
(cp_parser_unary_expression): Likewise.
* typeck.c (build_unary_op): Likewise.
* call.c (add_builtin_candidate, build_new_op): Likewise.
* error.c (dump_expr): Likewise.
* pt.c (tsubst_copy, tsubst_copy_and_build): Likewise.
* decl.c (ambi_op_p, grok_op_properties): Likewise.
* dump.c (dump_op): Likewise.
* lex.c (init_operators): Likewise.
* operators.def ("+"): Likewise.
* cp-gimplify.c (cp_gimplify_expr): Handle UNARY_PLUS_EXPR like a
conversion, if the result and argument types differ.
* tree.c (fold_if_not_in_template): Fold UNARY_PLUS_EXPR much
like a NOP_EXPR when !processing_template_decl.
* cxx-pretty-print.c (pp_cxx_cast_expression): Prototype.
(pp_cxx_unary_expression): Handle new UNARY_PLUS_EXPR tree code.
Co-Authored-By: Giovanni Bajo <giovannibajo@gcc.gnu.org>
From-SVN: r100285
+2005-05-27 Roger Sayle <roger@eyesopen.com>
+ Giovanni Bajo <giovannibajo@gcc.gnu.org>
+
+ * cp-tree.def (UNARY_PLUS_EXPR): New C++ unary tree code.
+ * parser.c (cp_parser_unary_expression): Use UNARY_PLUS_EXPR instead
+ of CONVERT_EXPR.
+ (cp_parser_unary_expression): Likewise.
+ * typeck.c (build_unary_op): Likewise.
+ * call.c (add_builtin_candidate, build_new_op): Likewise.
+ * error.c (dump_expr): Likewise.
+ * pt.c (tsubst_copy, tsubst_copy_and_build): Likewise.
+ * decl.c (ambi_op_p, grok_op_properties): Likewise.
+ * dump.c (dump_op): Likewise.
+ * lex.c (init_operators): Likewise.
+ * operators.def ("+"): Likewise.
+ * cp-gimplify.c (cp_gimplify_expr): Handle UNARY_PLUS_EXPR like a
+ conversion, if the result and argument types differ.
+ * tree.c (fold_if_not_in_template): Fold UNARY_PLUS_EXPR much
+ like a NOP_EXPR when !processing_template_decl.
+
+ * cxx-pretty-print.c (pp_cxx_cast_expression): Prototype.
+ (pp_cxx_unary_expression): Handle new UNARY_PLUS_EXPR tree code.
+
2005-05-27 Nathan Sidwell <nathan@codesourcery.com>
PR c++/21455
T operator+(T);
T operator-(T); */
- case CONVERT_EXPR: /* unary + */
+ case UNARY_PLUS_EXPR: /* unary + */
if (TREE_CODE (type1) == POINTER_TYPE)
break;
case NEGATE_EXPR:
case TRUTH_ORIF_EXPR:
return cp_build_binary_op (code, arg1, arg2);
- case CONVERT_EXPR:
+ case UNARY_PLUS_EXPR:
case NEGATE_EXPR:
case BIT_NOT_EXPR:
case TRUTH_NOT_EXPR:
ret = GS_OK;
break;
+ case UNARY_PLUS_EXPR:
+ {
+ tree arg = TREE_OPERAND (*expr_p, 0);
+ tree type = TREE_TYPE (*expr_p);
+ *expr_p = (TREE_TYPE (arg) != type) ? fold_convert (type, arg)
+ : arg;
+ ret = GS_OK;
+ }
+ break;
+
default:
ret = c_gimplify_expr (expr_p, pre_p, post_p);
break;
STMT_EXPR_STMT is the statement given by the expression. */
DEFTREECODE (STMT_EXPR, "stmt_expr", tcc_expression, 1)
+/* Unary plus. Operand 0 is the expression to which the unary plus
+ is applied. */
+DEFTREECODE (UNARY_PLUS_EXPR, "unary_plus_expr", tcc_unary, 1)
+
/*
Local variables:
mode:c
static void pp_cxx_abstract_declarator (cxx_pretty_printer *, tree);
static void pp_cxx_statement (cxx_pretty_printer *, tree);
static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
+static void pp_cxx_cast_expression (cxx_pretty_printer *, tree);
\f
static inline void
pp_unary_expression (pp, TREE_OPERAND (t, 0));
break;
+ case UNARY_PLUS_EXPR:
+ pp_plus (pp);
+ pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
+ break;
+
default:
pp_c_unary_expression (pp_c_base (pp), t);
break;
{
return (code == INDIRECT_REF
|| code == ADDR_EXPR
- || code == CONVERT_EXPR
+ || code == UNARY_PLUS_EXPR
|| code == NEGATE_EXPR
|| code == PREINCREMENT_EXPR
|| code == PREDECREMENT_EXPR);
operator_code = BIT_AND_EXPR;
break;
- case CONVERT_EXPR:
+ case UNARY_PLUS_EXPR:
operator_code = PLUS_EXPR;
break;
case VEC_DELETE_EXPR:
dump_string (di, "vecdelete");
break;
- case CONVERT_EXPR:
+ case UNARY_PLUS_EXPR:
dump_string (di, "pos");
break;
case NEGATE_EXPR:
pp_cxx_right_bracket (cxx_pp);
break;
- case CONVERT_EXPR:
+ case UNARY_PLUS_EXPR:
if (TREE_TYPE (t) && VOID_TYPE_P (TREE_TYPE (t)))
{
pp_cxx_left_paren (cxx_pp);
operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
operator_name_info [(int) RANGE_EXPR].name = "...";
- operator_name_info [(int) CONVERT_EXPR].name = "+";
+ operator_name_info [(int) UNARY_PLUS_EXPR].name = "+";
assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
= "(exact /=)";
DEF_SIMPLE_OPERATOR ("delete []", VEC_DELETE_EXPR, "da", -1)
/* Unary operators. */
-DEF_SIMPLE_OPERATOR ("+", CONVERT_EXPR, "ps", 1)
+DEF_SIMPLE_OPERATOR ("+", UNARY_PLUS_EXPR, "ps", 1)
DEF_SIMPLE_OPERATOR ("-", NEGATE_EXPR, "ng", 1)
DEF_SIMPLE_OPERATOR ("&", ADDR_EXPR, "ad", 1)
DEF_SIMPLE_OPERATOR ("*", INDIRECT_REF, "de", 1)
non_constant_p = (unary_operator == PREINCREMENT_EXPR
? "`++'" : "`--'");
/* Fall through. */
- case CONVERT_EXPR:
+ case UNARY_PLUS_EXPR:
case NEGATE_EXPR:
case TRUTH_NOT_EXPR:
expression = finish_unary_op_expr (unary_operator, cast_expression);
return ADDR_EXPR;
case CPP_PLUS:
- return CONVERT_EXPR;
+ return UNARY_PLUS_EXPR;
case CPP_MINUS:
return NEGATE_EXPR;
case TRUTH_NOT_EXPR:
case BIT_NOT_EXPR:
case ADDR_EXPR:
- case CONVERT_EXPR: /* Unary + */
+ case UNARY_PLUS_EXPR: /* Unary + */
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
case ARROW_EXPR:
case BIT_NOT_EXPR:
case ABS_EXPR:
case TRUTH_NOT_EXPR:
- case CONVERT_EXPR: /* Unary + */
+ case UNARY_PLUS_EXPR: /* Unary + */
case REALPART_EXPR:
case IMAGPART_EXPR:
return build_x_unary_op (TREE_CODE (t), RECUR (TREE_OPERAND (t, 0)));
"fold". We will call fold later when actually instantiating the
template. Integral constant expressions in templates will be
evaluated via fold_non_dependent_expr, as necessary. */
- return (processing_template_decl ? expr : fold (expr));
+ if (processing_template_decl)
+ return expr;
+
+ /* Fold C++ front-end specific tree codes. */
+ if (TREE_CODE (expr) == UNARY_PLUS_EXPR)
+ return fold_convert (TREE_TYPE (expr), TREE_OPERAND (expr, 0));
+
+ return fold (expr);
}
\f
switch (code)
{
- /* CONVERT_EXPR stands for unary plus in this context. */
- case CONVERT_EXPR:
+ case UNARY_PLUS_EXPR:
case NEGATE_EXPR:
{
int flags = WANT_ARITH | WANT_ENUM;
/* Unary plus (but not unary minus) is allowed on pointers. */
- if (code == CONVERT_EXPR)
+ if (code == UNARY_PLUS_EXPR)
flags |= WANT_POINTER;
arg = build_expr_type_conversion (flags, arg, true);
if (!arg)