With gcc (Debian 20201125-2) 11.0.0 20201125 (experimental) [master revision a4d9837ee4b:97273aee415:b13dacdfb315675803982ad5a3098f7b55e6357a] double f1 (void) { double d; int i; for (d = 2.0, i = 0; i < 5; i++, d *= d) ; return d; } double f2 (void) { volatile double d; int i; for (d = 2.0, i = 0; i < 5; i++, d *= d) ; return d; } yields the following incorrect warning when using "-Wunused-value": tst.c: In function 'f2': tst.c:17:10: warning: right-hand operand of comma expression has no effect [-Wunused-value] 17 | for (d = 2.0, i = 0; i < 5; i++, d *= d) | ~~^~~~~ Note that one gets a warning only for f2. The only difference is the "volatile". I found this when testing GNU MPFR (a similar code occurs in tests/tset_ld.c).
Confirmed, started with r11-5188-g32934a4f45a72144.
It seems with the changes to lvalue conversion the code volatile int x; int i; (x = 1, i = 2); gets rewritten to ((x = 1, 1), i = 2) and then build_compound_expr introduces the spurious warning. There is a another possible related issue: volatile int x; (x, 0); warns about warning: variable ‘x’ set but not used
It seems this does not happen anymore after fixing PR98047.
PATCH https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562465.html
I can confirm that.
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>: https://gcc.gnu.org/g:a000eb5918e09d28838ef572f4eea924d32db09b commit r11-6450-ga000eb5918e09d28838ef572f4eea924d32db09b Author: Martin Uecker <muecker@gwdg.de> Date: Mon Jan 4 22:53:58 2021 +0100 C: Add test for incorrect warning for assignment of certain volatile expressions fixed by commit 58a45ce [PR98029] 2021-01-04 Martin Uecker <muecker@gwdg.de> gcc/testsuite/ PR c/98029 * gcc.dg/pr98029.c: New test.