This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/81402] New: unhelpful -Wparentheses suggestion for assignment from non-zero constant
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 11 Jul 2017 22:18:53 +0000
- Subject: [Bug c/81402] New: unhelpful -Wparentheses suggestion for assignment from non-zero constant
- Auto-submitted: auto-generated
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
^