[Bug c++/90284] -Wunused-value points to the wrong expression

2021-09-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90284

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||diagnostic

--- Comment #2 from Andrew Pinski  ---
Testcase:
int incorrect_warning()
{
return (0 ? 0 : 0, 999);
}

int correct_warning()
{
return (0, 999);
}

[Bug c++/90284] -Wunused-value points to the wrong expression

2019-04-30 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90284

Martin Liška  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-04-30
 CC||dmalcolm at gcc dot gnu.org,
   ||marxin at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Martin Liška  ---
Confirmed. It's only related to C++, because for C we get:

gcc -Wunused-value pr90284.c 
pr90284.c: In function ‘incorrect_warning’:
pr90284.c:3:22: warning: left-hand operand of comma expression has no effect
[-Wunused-value]
3 | return (0 ? 0 : 0, 999);
  |  ^
pr90284.c: In function ‘correct_warning’:
pr90284.c:8:14: warning: left-hand operand of comma expression has no effect
[-Wunused-value]
8 | return (0, 999);
  |  ^

So a possible enhancement.

For C++ there was improvement of the second test-case by David in r267272:

pr90284.c:8:16: warning: left operand of comma operator has no effect
[-Wunused-value]
 return (0, 999);
^~~
after:
pr90284.c:8:13: warning: left operand of comma operator has no effect
[-Wunused-value]
8 | return (0, 999);
  | ^

I'm leaving that to David, hopefully he can fix it.