diff options
author | Joseph Myers <joseph@codesourcery.com> | 2005-08-06 12:31:49 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2005-08-06 12:31:49 +0100 |
commit | 591baeb02089799b46e5d320bc6f403d583fe3e9 (patch) | |
tree | 50083463eef147d4518d2138f1a14ce9e8fb18b7 /gcc/stmt.c | |
parent | f7a064b51430b3ba027c921786f1268c54cd1d5c (diff) | |
download | gcc-591baeb02089799b46e5d320bc6f403d583fe3e9.tar.gz |
re PR c/23113 (The -Wunused (value computed is not used) option missed an important case)
PR c/23113
* stmt.c (warn_if_unused_value): Check TREE_NO_WARNING at start.
Don't handle NOP_EXPR, CONVERT_EXPR and NON_LVALUE_EXPR
specially. Check for side effects only for COND_EXPR.
* c-typeck.c (c_finish_stmt_expr): Mark statement expression
return with TREE_NO_WARNING.
testsuite:
* gcc.dg/Wunused-value-1.c: New test.
From-SVN: r102805
Diffstat (limited to 'gcc/stmt.c')
-rw-r--r-- | gcc/stmt.c | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/gcc/stmt.c b/gcc/stmt.c index e38b96b6c29..ad75392010b 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -1373,7 +1373,7 @@ int warn_if_unused_value (tree exp, location_t locus) { restart: - if (TREE_USED (exp)) + if (TREE_USED (exp) || TREE_NO_WARNING (exp)) return 0; /* Don't warn about void constructs. This includes casting to void, @@ -1416,8 +1416,6 @@ warn_if_unused_value (tree exp, location_t locus) goto restart; case COMPOUND_EXPR: - if (TREE_NO_WARNING (exp)) - return 0; if (warn_if_unused_value (TREE_OPERAND (exp, 0), locus)) return 1; /* Let people do `(foo (), 0)' without a warning. */ @@ -1426,27 +1424,12 @@ warn_if_unused_value (tree exp, location_t locus) exp = TREE_OPERAND (exp, 1); goto restart; - case NOP_EXPR: - case CONVERT_EXPR: - case NON_LVALUE_EXPR: - /* Don't warn about conversions not explicit in the user's program. */ - if (TREE_NO_WARNING (exp)) + case COND_EXPR: + /* If this is an expression with side effects, don't warn; this + case commonly appears in macro expansions. */ + if (TREE_SIDE_EFFECTS (exp)) return 0; - /* Assignment to a cast usually results in a cast of a modify. - Don't complain about that. There can be an arbitrary number of - casts before the modify, so we must loop until we find the first - non-cast expression and then test to see if that is a modify. */ - { - tree tem = TREE_OPERAND (exp, 0); - - while (TREE_CODE (tem) == CONVERT_EXPR || TREE_CODE (tem) == NOP_EXPR) - tem = TREE_OPERAND (tem, 0); - - if (TREE_CODE (tem) == MODIFY_EXPR || TREE_CODE (tem) == INIT_EXPR - || TREE_CODE (tem) == CALL_EXPR) - return 0; - } - goto maybe_warn; + goto warn; case INDIRECT_REF: /* Don't warn about automatic dereferencing of references, since @@ -1470,11 +1453,7 @@ warn_if_unused_value (tree exp, location_t locus) if (EXPRESSION_CLASS_P (exp) && TREE_CODE_LENGTH (TREE_CODE (exp)) == 0) return 0; - maybe_warn: - /* If this is an expression with side effects, don't warn. */ - if (TREE_SIDE_EFFECTS (exp)) - return 0; - + warn: warning (0, "%Hvalue computed is not used", &locus); return 1; } |