diff options
author | Marek Polacek <polacek@redhat.com> | 2014-01-23 19:04:29 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-01-23 19:04:29 +0000 |
commit | 789eadcd54ffe62037461a4a22c2737ad9cbd01e (patch) | |
tree | 98eacc6f827b22b6ab595fbe3aaa8fffd51e38b5 /gcc/c | |
parent | 20f18c3ce14154eb477226aa48a12ebd32f9ead4 (diff) | |
download | gcc-789eadcd54ffe62037461a4a22c2737ad9cbd01e.zip gcc-789eadcd54ffe62037461a4a22c2737ad9cbd01e.tar.gz gcc-789eadcd54ffe62037461a4a22c2737ad9cbd01e.tar.bz2 |
re PR c/59871 (No unused value warning for comma expression)
PR c/59871
c/
* c-typeck.c (build_compound_expr): Warn even for right-hand operand
of a comma expression.
(emit_side_effect_warnings): Likewise.
libdecnumber/
* decNumberLocal.h (UBFROMUS, UBFROMUI): Remove last argument.
testsuite/
* gcc.dg/20020220-2.c: Adjust dg-warning message.
* gcc.dg/pr59871.c: New test.
From-SVN: r207002
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 34 |
2 files changed, 41 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index a158f11..237ac1a 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,10 @@ +2014-01-23 Marek Polacek <polacek@redhat.com> + + PR c/59871 + * c-typeck.c (build_compound_expr): Warn even for right-hand operand + of a comma expression. + (emit_side_effect_warnings): Likewise. + 2014-01-23 Balaji V. Iyer <balaji.v.iyer@intel.com> PR c/59825 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 92304b0..781d4df 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -4778,6 +4778,23 @@ build_compound_expr (location_t loc, tree expr1, tree expr2) "left-hand operand of comma expression has no effect"); } } + else if (TREE_CODE (expr1) == COMPOUND_EXPR + && warn_unused_value) + { + tree r = expr1; + location_t cloc = loc; + while (TREE_CODE (r) == COMPOUND_EXPR) + { + if (EXPR_HAS_LOCATION (r)) + cloc = EXPR_LOCATION (r); + r = TREE_OPERAND (r, 1); + } + if (!TREE_SIDE_EFFECTS (r) + && !VOID_TYPE_P (TREE_TYPE (r)) + && !CONVERT_EXPR_P (r)) + warning_at (cloc, OPT_Wunused_value, + "right-hand operand of comma expression has no effect"); + } /* With -Wunused, we should also warn if the left-hand operand does have side-effects, but computes a value which is not used. For example, in @@ -9643,6 +9660,23 @@ emit_side_effect_warnings (location_t loc, tree expr) if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr)) warning_at (loc, OPT_Wunused_value, "statement with no effect"); } + else if (TREE_CODE (expr) == COMPOUND_EXPR) + { + tree r = expr; + location_t cloc = loc; + while (TREE_CODE (r) == COMPOUND_EXPR) + { + if (EXPR_HAS_LOCATION (r)) + cloc = EXPR_LOCATION (r); + r = TREE_OPERAND (r, 1); + } + if (!TREE_SIDE_EFFECTS (r) + && !VOID_TYPE_P (TREE_TYPE (r)) + && !CONVERT_EXPR_P (r) + && !TREE_NO_WARNING (expr)) + warning_at (cloc, OPT_Wunused_value, + "right-hand operand of comma expression has no effect"); + } else warn_if_unused_value (expr, loc); } |