[Bug c/25733] missed diagnostic about assignment used as truth value.
vincent-gcc at vinc17 dot net
gcc-bugzilla@gcc.gnu.org
Fri Dec 9 15:35:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
--- Comment #13 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
Another example:
int f1 (int a, int b, int c, int d)
{
if (a = c && b == d)
return 0;
else
return 1;
}
int f2 (int a, int b, int c, int d)
{
if (a == b || (a = c && b == d))
return 0;
else
return 1;
}
int f3 (int a, int b, int c, int d)
{
if (a == b && (a = c && b == d))
return 0;
else
return 1;
}
GCC emits a warning for f1 (this is the usual case), but neither for f2, nor
for f3. Note that for f2, the parentheses around what should be a == c && b ==
d are optional, but strongly recommended (GCC has a warning for that), so one
would really expect
if (a == b || (a == c && b == d))
or
if (a == b || ((a = c && b == d)))
For f3, the parentheses around what should be a == c && b == d are not
specially recommended (but may be useful to emphasize on some symmetry in some
context), but I think that there should be the same rule as f2.
FYI, MPFR had an undetected bug corresponding to f3 and a warning would have
really been useful:
https://gforge.inria.fr/scm/viewvc.php/mpfr/trunk/src/sqrt.c?r1=11021&r2=11022
More information about the Gcc-bugs
mailing list