diff options
author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2009-04-19 11:04:13 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2009-04-19 11:04:13 +0000 |
commit | ca409efd9282623758e9b8f36df75cdd7278a3e1 (patch) | |
tree | bcaf465ab5ba49fd67b08ce44d9d4349c54cc20e /gcc/cp | |
parent | c93c8cf442616849535c5ec3a50d517ad76fe5d3 (diff) | |
download | gcc-ca409efd9282623758e9b8f36df75cdd7278a3e1.zip gcc-ca409efd9282623758e9b8f36df75cdd7278a3e1.tar.gz gcc-ca409efd9282623758e9b8f36df75cdd7278a3e1.tar.bz2 |
re PR c/32061 ((Wlogical-op) wording of warning of constant logicials need improvement)
2009-04-19 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/32061
PR c++/36954
* doc/invoke.texi: Add -Wlogical-op to -Wextra.
* common.opt (Wlogical-op): Move from here...
* c.opt (Wlogical-op): ... to here.
* c-typeck.c (parser_build_binary_op): Update call to
warn_logical_operator.
* c-opts.c (c_common_post_options): Enable warn_logical_op with
extra_warnings.
* c-common.c (warn_logical_op): Update.
* c-common.h (warn_logical_op): Update declaration.
cp/
* call.c (build_new_op): Save the original codes of operands
before folding.
testsuite/
* gcc.dg/pr32061.c: New.
* gcc.dg/Wlogical-op-1.c: Update.
* g++.dg/warn/Wlogical-op-1.C: Update.
* g++.dg/warn/pr36954.C: New.
From-SVN: r146344
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/call.c | 28 |
2 files changed, 24 insertions, 11 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bfa05e5..259aa8e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2009-04-19 Manuel López-Ibáñez <manu@gcc.gnu.org> + + PR c/32061 + PR c++/36954 + * call.c (build_new_op): Save the original codes of operands + before folding. + 2009-04-18 Kazu Hirata <kazu@codesourcery.com> * cp-tree.h: Remove the prototype for insert_block. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f6c24b6..feb3004 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3897,11 +3897,12 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, tree result = NULL_TREE; bool result_valid_p = false; enum tree_code code2 = NOP_EXPR; + enum tree_code code_orig_arg1 = ERROR_MARK; + enum tree_code code_orig_arg2 = ERROR_MARK; conversion *conv; void *p; bool strict_p; bool any_viable_p; - bool expl_eq_arg1 = false; if (error_operand_p (arg1) || error_operand_p (arg2) @@ -3935,8 +3936,10 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, case TRUTH_ANDIF_EXPR: case TRUTH_AND_EXPR: case TRUTH_OR_EXPR: - if (COMPARISON_CLASS_P (arg1)) - expl_eq_arg1 = true; + /* These are saved for the sake of warn_logical_operator. */ + code_orig_arg1 = TREE_CODE (arg1); + code_orig_arg2 = TREE_CODE (arg2); + default: break; } @@ -4140,8 +4143,16 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, if (conv->kind == ck_ref_bind) conv = conv->u.next; arg1 = convert_like (conv, arg1, complain); + if (arg2) { + /* We need to call warn_logical_operator before + converting arg2 to a boolean_type. */ + if (complain & tf_warning) + warn_logical_operator (input_location, code, + code_orig_arg1, arg1, + code_orig_arg2, arg2); + conv = cand->convs[1]; if (conv->kind == ck_ref_bind) conv = conv->u.next; @@ -4155,12 +4166,6 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, arg3 = convert_like (conv, arg3, complain); } - if (!expl_eq_arg1) - { - if (complain & tf_warning) - warn_logical_operator (code, arg1, arg2); - expl_eq_arg1 = true; - } } } @@ -4185,8 +4190,9 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, case TRUTH_ORIF_EXPR: case TRUTH_AND_EXPR: case TRUTH_OR_EXPR: - if (!expl_eq_arg1) - warn_logical_operator (code, arg1, arg2); + warn_logical_operator (input_location, code, + code_orig_arg1, arg1, code_orig_arg2, arg2); + /* Fall through. */ case PLUS_EXPR: case MINUS_EXPR: case MULT_EXPR: |