diff options
Diffstat (limited to 'gcc/cp/typeck.c')
-rw-r--r-- | gcc/cp/typeck.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index a591d291602..c53a85a16e0 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2208,16 +2208,16 @@ rationalize_conditional_expr (enum tree_code code, tree t, op1, TREE_CODE (op1), /*overload=*/NULL, complain), - cp_build_unary_op (code, op0, 0, complain), - cp_build_unary_op (code, op1, 0, complain), + cp_build_unary_op (code, op0, false, complain), + cp_build_unary_op (code, op1, false, complain), complain); } return build_conditional_expr (loc, TREE_OPERAND (t, 0), - cp_build_unary_op (code, TREE_OPERAND (t, 1), 0, + cp_build_unary_op (code, TREE_OPERAND (t, 1), false, complain), - cp_build_unary_op (code, TREE_OPERAND (t, 2), 0, + cp_build_unary_op (code, TREE_OPERAND (t, 2), false, complain), complain); } @@ -5036,8 +5036,8 @@ cp_build_binary_op (location_t location, if (first_complex) { op0 = save_expr (op0); - real = cp_build_unary_op (REALPART_EXPR, op0, 1, complain); - imag = cp_build_unary_op (IMAGPART_EXPR, op0, 1, complain); + real = cp_build_unary_op (REALPART_EXPR, op0, true, complain); + imag = cp_build_unary_op (IMAGPART_EXPR, op0, true, complain); switch (code) { case MULT_EXPR: @@ -5056,8 +5056,8 @@ cp_build_binary_op (location_t location, else { op1 = save_expr (op1); - real = cp_build_unary_op (REALPART_EXPR, op1, 1, complain); - imag = cp_build_unary_op (IMAGPART_EXPR, op1, 1, complain); + real = cp_build_unary_op (REALPART_EXPR, op1, true, complain); + imag = cp_build_unary_op (IMAGPART_EXPR, op1, true, complain); switch (code) { case MULT_EXPR: @@ -5784,11 +5784,10 @@ cp_build_addr_expr_strict (tree arg, tsubst_flags_t complain) from aggregates to types we don't yet know we want? (Or are those cases typically errors which should be reported?) - NOCONVERT nonzero suppresses the default promotions - (such as from short to int). */ + NOCONVERT suppresses the default promotions (such as from short to int). */ tree -cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, +cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert, tsubst_flags_t complain) { /* No default_conversion here. It causes trouble for ADDR_EXPR. */ @@ -5920,9 +5919,9 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, tree real, imag; arg = cp_stabilize_reference (arg); - real = cp_build_unary_op (REALPART_EXPR, arg, 1, complain); - imag = cp_build_unary_op (IMAGPART_EXPR, arg, 1, complain); - real = cp_build_unary_op (code, real, 1, complain); + real = cp_build_unary_op (REALPART_EXPR, arg, true, complain); + imag = cp_build_unary_op (IMAGPART_EXPR, arg, true, complain); + real = cp_build_unary_op (code, real, true, complain); if (real == error_mark_node || imag == error_mark_node) return error_mark_node; return build2 (COMPLEX_EXPR, TREE_TYPE (arg), @@ -6030,16 +6029,32 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, complain)) return error_mark_node; - /* Forbid using -- on `bool'. */ + /* Forbid using -- or ++ in C++17 on `bool'. */ if (TREE_CODE (declared_type) == BOOLEAN_TYPE) { if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR) { if (complain & tf_error) - error ("invalid use of Boolean expression as operand " - "to %<operator--%>"); + error ("use of an operand of type %qT in %<operator--%> " + "is forbidden", boolean_type_node); return error_mark_node; } + else + { + if (cxx_dialect >= cxx1z) + { + if (complain & tf_error) + error ("use of an operand of type %qT in " + "%<operator++%> is forbidden in C++1z", + boolean_type_node); + return error_mark_node; + } + /* Otherwise, [depr.incr.bool] says this is deprecated. */ + else if (!in_system_header_at (input_location)) + warning (OPT_Wdeprecated, "use of an operand of type %qT " + "in %<operator++%> is deprecated", + boolean_type_node); + } val = boolean_increment (code, arg); } else if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR) @@ -6076,7 +6091,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, /* Hook for the c-common bits that build a unary op. */ tree build_unary_op (location_t /*location*/, - enum tree_code code, tree xarg, int noconvert) + enum tree_code code, tree xarg, bool noconvert) { return cp_build_unary_op (code, xarg, noconvert, tf_warning_or_error); } @@ -6100,7 +6115,7 @@ unary_complex_lvalue (enum tree_code code, tree arg) /* Handle (a, b) used as an "lvalue". */ if (TREE_CODE (arg) == COMPOUND_EXPR) { - tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 1), 0, + tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 1), false, tf_warning_or_error); return build2 (COMPOUND_EXPR, TREE_TYPE (real_result), TREE_OPERAND (arg, 0), real_result); @@ -6134,7 +6149,7 @@ unary_complex_lvalue (enum tree_code code, tree arg) if (TREE_CODE (arg) == MODIFY_EXPR || TREE_CODE (arg) == INIT_EXPR) { - tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 0), 0, + tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 0), false, tf_warning_or_error); arg = build2 (COMPOUND_EXPR, TREE_TYPE (real_result), arg, real_result); |