diff options
author | Marek Polacek <polacek@redhat.com> | 2015-12-16 16:50:07 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2015-12-16 16:50:07 +0000 |
commit | d06f8b75bd1d2bda101444a44b0a953a4b9895b3 (patch) | |
tree | 8824cacf00f8d245e1b4918e155559a0034d43a6 /gcc | |
parent | bc32563724b72651d0a2040ed672f96e988f7cee (diff) | |
download | gcc-d06f8b75bd1d2bda101444a44b0a953a4b9895b3.zip gcc-d06f8b75bd1d2bda101444a44b0a953a4b9895b3.tar.gz gcc-d06f8b75bd1d2bda101444a44b0a953a4b9895b3.tar.bz2 |
re PR c/64637 (Incorrect location for -Wunused-value warnings in for-loop)
PR c/64637
* c-typeck.c (c_process_expr_stmt): Use location of the expression if
available.
* gcc.dg/pr64637.c: New test.
From-SVN: r231700
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr64637.c | 25 |
4 files changed, 37 insertions, 1 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index e61a2ed..fd1c707 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2015-12-16 Marek Polacek <polacek@redhat.com> + + PR c/64637 + * c-typeck.c (c_process_expr_stmt): Use location of the expression if + available. + 2015-12-15 Marek Polacek <polacek@redhat.com> PR c/68907 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 9d6c604..a147ac6 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -10131,7 +10131,7 @@ c_process_expr_stmt (location_t loc, tree expr) out which is the result. */ if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list) && warn_unused_value) - emit_side_effect_warnings (loc, expr); + emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr, loc), expr); exprv = expr; while (TREE_CODE (exprv) == COMPOUND_EXPR) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ebc8903..7a66b14 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-12-16 Marek Polacek <polacek@redhat.com> + + PR c/64637 + * gcc.dg/pr64637.c: New test. + 2015-12-16 Nathan Sidwell <nathan@acm.org> * gcc.dg/sibcall-9.c: Xfail for nvptx. diff --git a/gcc/testsuite/gcc.dg/pr64637.c b/gcc/testsuite/gcc.dg/pr64637.c new file mode 100644 index 0000000..779ff50 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr64637.c @@ -0,0 +1,25 @@ +/* PR c/64637 */ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + +void g (); + +void +f (int b) +{ + for (int i = 0; i < b; i + b) /* { dg-warning "28:statement with no effect" } */ + g (); + // PARM_DECLs still don't have a location, don't expect an exact location. + for (int i = 0; i < b; b) /* { dg-warning "statement with no effect" } */ + g (); + for (int i = 0; i < b; !i) /* { dg-warning "26:statement with no effect" } */ + g (); + for (!b;;) /* { dg-warning "8:statement with no effect" } */ + g (); + for (;; b * 2) /* { dg-warning "13:statement with no effect" } */ + g (); + ({ + b / 5; /* { dg-warning "8:statement with no effect" } */ + b ^ 5; + }); +} |