Re: [C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
On Wed, 22 Jan 2014, Marek Polacek wrote: > 2014-01-22 Marek Polacek > > 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. OK. -- Joseph S. Myers jos...@codesourcery.com
Re: [C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
On Wed, Jan 22, 2014 at 12:15:00AM +0100, Jakub Jelinek wrote: > And for > (bar (), (bar (), (bar (), (bar (), (bar (), (bar (), (bar (), 7))); > ? Argh, for this one we've got COMPOUND_EXPRs even in TREE_OPERAND (r, 1). Fixed & sorry. > On the other side, there is warn_if_unused_value, which specifically has: > /* Let people do `(foo (), 0)' without a warning. */ > if (TREE_CONSTANT (TREE_OPERAND (exp, 1))) > return false; > so perhaps it is intentional that we don't warn about this? > That stuff dates all the way back to r759. Though I wonder why it would > be desirable to warn about this for C++ and not for C. This is confusing. I'll try to sumarize what I see. Let A, B, C, D be stmts: A: bar (), 1; B: (bar (), 1); C: bar (), 5 * i; D: (bar (), 5 * i); C++ warns on A and C ("right operand..."), those parentheses suppress warnings. C before patch warns on C and D with "value computed is not used". C with my patch warns on A, B, C, and D with "right-hand operand...". I think what my patch does should be desirable. I added a few more tests into the testcase. 2014-01-22 Marek Polacek 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. --- gcc/libdecnumber/decNumberLocal.h.mp2014-01-21 18:34:32.235540589 +0100 +++ gcc/libdecnumber/decNumberLocal.h 2014-01-21 22:04:34.331223218 +0100 @@ -153,10 +153,9 @@ see the files COPYING3 and COPYING.RUNTI #define UBTOUI(b) (memcpy((void *)&uiwork, b, 4), uiwork) /* Store a uInt, etc., into bytes starting at a char* or uByte*.*/ - /* Returns i, evaluated, for convenience; has to use uiwork because */ - /* i may be an expression. */ - #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), uswork) - #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), uiwork) + /* Has to use uiwork because i may be an expression. */ + #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2)) + #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4)) /* X10 and X100 -- multiply integer i by 10 or 100 */ /* [shifts are usually faster than multiply; could be conditional] */ --- gcc/gcc/c/c-typeck.c.mp 2014-01-21 11:59:33.221215248 +0100 +++ gcc/gcc/c/c-typeck.c2014-01-22 11:04:51.681894533 +0100 @@ -4776,6 +4776,23 @@ build_compound_expr (location_t loc, tre "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 @@ -9641,6 +9658,23 @@ emit_side_effect_warnings (location_t lo 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); } --- gcc/gcc/testsuite/gcc.dg/20020220-2.c.mp2014-01-21 14:47:58.888754509 +0100 +++ gcc/gcc/testsuite/gcc.dg/20020220-2.c 2014-01-21 23:13:23.758405040 +0100 @@ -1,5 +1,5 @@ /* PR c/4697 - Test whether value computed not used warning is given for compound + Test whether operand has no effect warning is given for compound expression. */ /* { dg-do compile } */ /* { dg-options "-O2 -Wunused" } */ @@ -7,6 +7,6 @@ int b; int foo (int a) { - a = a + 1, 5 * b;/* { dg-warning "value computed is not used" } */ + a = a + 1, 5 * b; /* { dg-warning "right-hand oper
Re: [C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
On Tue, Jan 21, 2014 at 11:54:03PM +0100, Marek Polacek wrote: > On Tue, Jan 21, 2014 at 11:34:42PM +0100, Jakub Jelinek wrote: > > On Tue, Jan 21, 2014 at 11:30:58PM +0100, Marek Polacek wrote: > > > I made another small change: in the second hunk, in > > > emit_side_effect_warnings, I got rid of the while, since it seems to > > > me we never get COMPOUND_EXPR in TREE_OPERAND (r, 1). > > > > For bar (), 1, 2, 3, 4, 5, 6, 7, 8; sure, but what about > > (1, (2, (3, (4, (5, (6, (bar (), 7))); ? > > For that `expr' that emit_side_effect_warnings gets is: > type size > unit size > align 32 symtab 0 alias set -1 canonical type 0x7ffe27144690 > precision 32 min max 0x7ffe27146380 2147483647> > pointer_to_this > > side-effects > arg 0 > side-effects > fn > constant arg 0 > uu.c:19:32> > uu.c:19:32> > arg 1 > constant 7> > uu.c:19:5> > so we should be fine even in that case. And for (bar (), (bar (), (bar (), (bar (), (bar (), (bar (), (bar (), 7))); ? On the other side, there is warn_if_unused_value, which specifically has: /* Let people do `(foo (), 0)' without a warning. */ if (TREE_CONSTANT (TREE_OPERAND (exp, 1))) return false; so perhaps it is intentional that we don't warn about this? That stuff dates all the way back to r759. Though I wonder why it would be desirable to warn about this for C++ and not for C. Jakub
Re: [C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
On Tue, Jan 21, 2014 at 11:34:42PM +0100, Jakub Jelinek wrote: > On Tue, Jan 21, 2014 at 11:30:58PM +0100, Marek Polacek wrote: > > I made another small change: in the second hunk, in > > emit_side_effect_warnings, I got rid of the while, since it seems to > > me we never get COMPOUND_EXPR in TREE_OPERAND (r, 1). > > For bar (), 1, 2, 3, 4, 5, 6, 7, 8; sure, but what about > (1, (2, (3, (4, (5, (6, (bar (), 7))); ? For that `expr' that emit_side_effect_warnings gets is: unit size align 32 symtab 0 alias set -1 canonical type 0x7ffe27144690 precision 32 min max pointer_to_this > side-effects arg 0 side-effects fn constant arg 0 uu.c:19:32> uu.c:19:32> arg 1 constant 7> uu.c:19:5> so we should be fine even in that case. Marek
Re: [C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
On Tue, Jan 21, 2014 at 11:30:58PM +0100, Marek Polacek wrote: > I made another small change: in the second hunk, in > emit_side_effect_warnings, I got rid of the while, since it seems to > me we never get COMPOUND_EXPR in TREE_OPERAND (r, 1). For bar (), 1, 2, 3, 4, 5, 6, 7, 8; sure, but what about (1, (2, (3, (4, (5, (6, (bar (), 7))); ? Jakub
Re: [C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
On Tue, Jan 21, 2014 at 07:50:13PM +0100, Jakub Jelinek wrote: > On Tue, Jan 21, 2014 at 07:38:10PM +0100, Marek Polacek wrote: > > --- gcc/gcc/c/c-typeck.c.mp 2014-01-21 11:59:33.221215248 +0100 > > +++ gcc/gcc/c/c-typeck.c2014-01-21 18:10:53.900279750 +0100 > > @@ -4757,6 +4757,18 @@ build_compound_expr (location_t loc, tre > >expr2 = TREE_OPERAND (expr2, 0); > > } > > > > + if (TREE_CODE (expr1) == COMPOUND_EXPR > > + && warn_unused_value) > > +{ > > + tree r = expr1; > > + while (TREE_CODE (r) == COMPOUND_EXPR) > > +r = TREE_OPERAND (r, 1); > > + if (!TREE_SIDE_EFFECTS (r) > > + && !VOID_TYPE_P (TREE_TYPE (r)) > > + && !CONVERT_EXPR_P (r)) > > + warning_at (loc, OPT_Wunused_value, > > + "right-hand operand of comma expression has no effect"); > > +} > >if (!TREE_SIDE_EFFECTS (expr1)) > > { > >/* The left-hand operand of a comma expression is like an expression > > Won't this warn twice if !TREE_SIDE_EFFECTS (expr1) and expr1 is a > COMPOUND_EXPR? I would be expecting this whole if as else if below the > !TREE_SIDE_EFFECTS case. I mean, in emit_side_effect_warnings you do it > the same way, and if nothing in the expr1 COMPOUND_EXPR has any > !side-effects, then it is ok to complain about the expr1 as whole, no > need to complain particularly about the rhs of it. Ooops, for some reason I moved the whole if above. I've changed it so it's the same as in the emit_side_effect_warnings now, meaning that for 1, 1, 1; we emit what GCC 4.8 emits. > Also, shouldn't you use EXPR_LOCATION of the COMPOUND_EXPR r is rhs of > in the end? I.e. do something like: > location_t cloc = loc; > while (TREE_CODE (r) == COMPOUND_EXPR) > { > if (EXPR_HAS_LOCATION (r)) cloc = EXPR_LOCATION (r); > r = TREE_OPERAND (r, 1); > } > and use cloc in warning_at. Yes, this produces better locus, so thanks for the hint. I made another small change: in the second hunk, in emit_side_effect_warnings, I got rid of the while, since it seems to me we never get COMPOUND_EXPR in TREE_OPERAND (r, 1). Furthermore, I incorporated a change into decNumberLocal.h, which Marc suggested. Regtested/bootstrapped on x86_64-linux, ok for trunk? 2014-01-21 Marek Polacek PR c/59871 c/ * c-typeck.c (build_compound_expr): Warn even for right-hand operand of 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. --- gcc/libdecnumber/decNumberLocal.h.mp2014-01-21 18:34:32.235540589 +0100 +++ gcc/libdecnumber/decNumberLocal.h 2014-01-21 22:04:34.331223218 +0100 @@ -153,10 +153,9 @@ see the files COPYING3 and COPYING.RUNTI #define UBTOUI(b) (memcpy((void *)&uiwork, b, 4), uiwork) /* Store a uInt, etc., into bytes starting at a char* or uByte*.*/ - /* Returns i, evaluated, for convenience; has to use uiwork because */ - /* i may be an expression. */ - #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), uswork) - #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), uiwork) + /* Has to use uiwork because i may be an expression. */ + #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2)) + #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4)) /* X10 and X100 -- multiply integer i by 10 or 100 */ /* [shifts are usually faster than multiply; could be conditional] */ --- gcc/gcc/c/c-typeck.c.mp 2014-01-21 11:59:33.221215248 +0100 +++ gcc/gcc/c/c-typeck.c2014-01-21 22:06:32.349778039 +0100 @@ -4776,6 +4776,23 @@ build_compound_expr (location_t loc, tre "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 @@ -9641,6 +9658,16 @@ emit_side_effect_warnings (location_t lo 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 = TREE_OPERAND (ex
Re: [C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
On Tue, Jan 21, 2014 at 09:18:17PM +0100, Marc Glisse wrote: > On Tue, 21 Jan 2014, Marek Polacek wrote: > > >--- gcc/libdecnumber/decNumberLocal.h.mp 2014-01-21 18:34:32.235540589 > >+0100 > >+++ gcc/libdecnumber/decNumberLocal.h2014-01-21 19:04:12.173243034 > >+0100 > >@@ -155,8 +155,10 @@ see the files COPYING3 and COPYING.RUNTI > > /* Store a uInt, etc., into bytes starting at a char* or uByte*.*/ > > /* Returns i, evaluated, for convenience; has to use uiwork because */ > > /* i may be an expression. */ > >- #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), > >uswork) > >- #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), > >uiwork) > >+ #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), \ > >+ (void)uswork) > >+ #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), \ > >+ (void)uiwork) > > This looks wrong to me. The comment before says that those macros > "return" uiwork, so you can't cast it to void in the macro. Options: > > 1) cast to void in the users of the macro: > (void) UBFROMUS(acc+4, 0); > > 2) Make the macros not return (since none of the users use the > return value), i.e. remove ", uiwork" at the end and update the > comment before. (you may need to cast the return of memcpy to void, > which makes more sense) I went with 2). Still it looks kind of weird, but I don't care enough as long as it bootstraps ;). I'll post a patch once the regtesting finishes. Thanks. Marek
Re: [C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
On Tue, 21 Jan 2014, Marek Polacek wrote: --- gcc/libdecnumber/decNumberLocal.h.mp2014-01-21 18:34:32.235540589 +0100 +++ gcc/libdecnumber/decNumberLocal.h 2014-01-21 19:04:12.173243034 +0100 @@ -155,8 +155,10 @@ see the files COPYING3 and COPYING.RUNTI /* Store a uInt, etc., into bytes starting at a char* or uByte*.*/ /* Returns i, evaluated, for convenience; has to use uiwork because */ /* i may be an expression. */ - #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), uswork) - #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), uiwork) + #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), \ + (void)uswork) + #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), \ + (void)uiwork) This looks wrong to me. The comment before says that those macros "return" uiwork, so you can't cast it to void in the macro. Options: 1) cast to void in the users of the macro: (void) UBFROMUS(acc+4, 0); 2) Make the macros not return (since none of the users use the return value), i.e. remove ", uiwork" at the end and update the comment before. (you may need to cast the return of memcpy to void, which makes more sense) -- Marc Glisse
Re: [C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
On Tue, Jan 21, 2014 at 07:38:10PM +0100, Marek Polacek wrote: > --- gcc/gcc/c/c-typeck.c.mp 2014-01-21 11:59:33.221215248 +0100 > +++ gcc/gcc/c/c-typeck.c 2014-01-21 18:10:53.900279750 +0100 > @@ -4757,6 +4757,18 @@ build_compound_expr (location_t loc, tre >expr2 = TREE_OPERAND (expr2, 0); > } > > + if (TREE_CODE (expr1) == COMPOUND_EXPR > + && warn_unused_value) > +{ > + tree r = expr1; > + while (TREE_CODE (r) == COMPOUND_EXPR) > +r = TREE_OPERAND (r, 1); > + if (!TREE_SIDE_EFFECTS (r) > + && !VOID_TYPE_P (TREE_TYPE (r)) > + && !CONVERT_EXPR_P (r)) > + warning_at (loc, OPT_Wunused_value, > + "right-hand operand of comma expression has no effect"); > +} >if (!TREE_SIDE_EFFECTS (expr1)) > { >/* The left-hand operand of a comma expression is like an expression Won't this warn twice if !TREE_SIDE_EFFECTS (expr1) and expr1 is a COMPOUND_EXPR? I would be expecting this whole if as else if below the !TREE_SIDE_EFFECTS case. I mean, in emit_side_effect_warnings you do it the same way, and if nothing in the expr1 COMPOUND_EXPR has any !side-effects, then it is ok to complain about the expr1 as whole, no need to complain particularly about the rhs of it. Also, shouldn't you use EXPR_LOCATION of the COMPOUND_EXPR r is rhs of in the end? I.e. do something like: location_t cloc = loc; while (TREE_CODE (r) == COMPOUND_EXPR) { if (EXPR_HAS_LOCATION (r)) cloc = EXPR_LOCATION (r); r = TREE_OPERAND (r, 1); } and use cloc in warning_at. Jakub
[C PATCH] Warn about unused RHS of COMPOUND_EXPR (PR c/59871)
In this PR the problem was that the C FE, unlike the C++ FE, didn't warn on e.g. bar (), 1;, that the RHS has no effect. This patch tries to tweak the C FE so that it follows what the C++ FE does. Note that the C++ FE uses quite imprecise locus info; the C FE's info is better. I had to slightly adjust one testcase and a header in libdecnumber. Regtested/bootstrapped on x86_64-linux, ok for trunk? 2014-01-21 Marek Polacek PR c/59871 c/ * c-typeck.c (build_compound_expr): Warn even for right-hand operand of comma expression. (emit_side_effect_warnings): Likewise. libdecnumber/ * decNumberLocal.h (UBFROMUS, UBFROMUI): Cast last argument to void. testsuite/ * gcc.dg/20020220-2.c: Adjust dg-warning message. * gcc.dg/pr59871.c: New test. --- gcc/libdecnumber/decNumberLocal.h.mp2014-01-21 18:34:32.235540589 +0100 +++ gcc/libdecnumber/decNumberLocal.h 2014-01-21 19:04:12.173243034 +0100 @@ -155,8 +155,10 @@ see the files COPYING3 and COPYING.RUNTI /* Store a uInt, etc., into bytes starting at a char* or uByte*.*/ /* Returns i, evaluated, for convenience; has to use uiwork because */ /* i may be an expression. */ - #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), uswork) - #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), uiwork) + #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), \ + (void)uswork) + #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), \ + (void)uiwork) /* X10 and X100 -- multiply integer i by 10 or 100 */ /* [shifts are usually faster than multiply; could be conditional] */ --- gcc/gcc/c/c-typeck.c.mp 2014-01-21 11:59:33.221215248 +0100 +++ gcc/gcc/c/c-typeck.c2014-01-21 18:10:53.900279750 +0100 @@ -4757,6 +4757,18 @@ build_compound_expr (location_t loc, tre expr2 = TREE_OPERAND (expr2, 0); } + if (TREE_CODE (expr1) == COMPOUND_EXPR + && warn_unused_value) +{ + tree r = expr1; + while (TREE_CODE (r) == COMPOUND_EXPR) +r = TREE_OPERAND (r, 1); + if (!TREE_SIDE_EFFECTS (r) + && !VOID_TYPE_P (TREE_TYPE (r)) + && !CONVERT_EXPR_P (r)) + warning_at (loc, OPT_Wunused_value, + "right-hand operand of comma expression has no effect"); +} if (!TREE_SIDE_EFFECTS (expr1)) { /* The left-hand operand of a comma expression is like an expression @@ -9641,6 +9653,18 @@ emit_side_effect_warnings (location_t lo 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; + while (TREE_CODE (r) == COMPOUND_EXPR) +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 (EXPR_LOC_OR_LOC (expr, loc), OPT_Wunused_value, + "right-hand operand of comma expression has no effect"); +} else warn_if_unused_value (expr, loc); } --- gcc/gcc/testsuite/gcc.dg/20020220-2.c.mp2014-01-21 14:47:58.888754509 +0100 +++ gcc/gcc/testsuite/gcc.dg/20020220-2.c 2014-01-21 15:04:53.700441224 +0100 @@ -1,5 +1,5 @@ /* PR c/4697 - Test whether value computed not used warning is given for compound + Test whether operand has no effect warning is given for compound expression. */ /* { dg-do compile } */ /* { dg-options "-O2 -Wunused" } */ @@ -7,6 +7,6 @@ int b; int foo (int a) { - a = a + 1, 5 * b;/* { dg-warning "value computed is not used" } */ + a = a + 1, 5 * b; /* { dg-warning "right operand of comma operator has no effect" } */ return a; } --- gcc/gcc/testsuite/gcc.dg/pr59871.c.mp 2014-01-21 16:17:49.0 +0100 +++ gcc/gcc/testsuite/gcc.dg/pr59871.c 2014-01-21 16:13:39.0 +0100 @@ -0,0 +1,15 @@ +/* PR c/59871 */ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + +extern int bar (); + +void +foo (int *p) +{ + p[0] = (bar (), 1, bar ()); /* { dg-warning "right-hand operand of comma expression has no effect" } */ + p[1] = (1, bar ()); /* { dg-warning "left-hand operand of comma expression has no effect" } */ + bar (), 1, bar (); /* { dg-warning "right-hand operand of comma expression has no effect" } */ + bar (), 1; /* { dg-warning "right-hand operand of comma expression has no effect" } */ + 1, bar (); /* { dg-warning "left-hand operand of comma expression has no effect" } */ +} Marek