[Bug c/81402] New: unhelpful -Wparentheses suggestion for assignment from non-zero constant
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jul 11 22:18:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81402
Bug ID: 81402
Summary: unhelpful -Wparentheses suggestion for assignment from
non-zero constant
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: trivial
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
In response to a controlling expression in an if statement that is an
assignment expression, -Wparentheses suggests to enclose the expression in
parentheses. That suggestion is only helpful in cases where the value of right
operand of the assignment is unknown. Otherwise, when its value is constant,
and especially when the operand is a literal, the assignment is almost
certainly wrong because testing the value of a constant for equality to zero is
pointless. In those cases, pointing out the likely mistake rather than
suggesting to use parentheses would be more helpful.
$ cat a.c && gcc -S -Wall a.c
oid f (int i, int j)
{
if (i = j) { } // assignment could be intended
}
void g (int i)
{
if (i = 1) { } // assignment almost certainly not intended
}
a.c: In function ‘f’:
a.c:3:7: warning: suggest parentheses around assignment used as truth value
[-Wparentheses]
if (i = j) { } // assignment could be intended
^
a.c: In function ‘g’:
a.c:8:7: warning: suggest parentheses around assignment used as truth value
[-Wparentheses]
if (i = 1) { } // assignment almost certainly not intended
^
More information about the Gcc-bugs
mailing list