This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51545] New: missing -Wparentheses diagnostic with compound assignment used as condition
- From: "manu at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 14 Dec 2011 01:04:23 +0000
- Subject: [Bug c++/51545] New: missing -Wparentheses diagnostic with compound assignment used as condition
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51545
Bug #: 51545
Summary: missing -Wparentheses diagnostic with compound
assignment used as condition
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: manu@gcc.gnu.org
Noticed here:
http://llvm.org/devmtg/2011-11/Weber_Wennborg_UsingClangInChromium.pdf
Testcase:
int foo(int x, int y)
{
if (x|=y) return 0;
return 1;
}
gcc 4.7 -Wall -Wextra -Wparentheses -Wlogical-op -Wtype-limits prints nothing.
clang 3.0 without extra flags:
test.cc:3:8: warning: using the result of an assignment as a condition without
parentheses [-Wparentheses]
if (x|=y) return 0;
~^~~
test.cc:3:8: note: place parentheses around the assignment to silence this
warning
if (x|=y) return 0;
^
( )
test.cc:3:8: note: use '!=' to turn this compound assignment into an inequality
comparison
if (x|=y) return 0;
^~
!=
1 warning generated.
Nonetheless, I still believe that using extra parentheses to silence these
warnings actually hides bugs and there are better alternatives. See PR25733.