This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/29193] New: Warning on if(a < b < c) and other similar codes
- From: "alpt at freaknet dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Sep 2006 16:21:01 -0000
- Subject: [Bug c/29193] New: Warning on if(a < b < c) and other similar codes
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Consider this code:
if(a <= b <= c)
something();
If c is >= 1, then the `if' will always execute something(), because `a <= b'
returns either 0 or 1.
This, obviously, is not an error, but it can mislead some programmers,
therefore it would be nice to have a warning like "warning: suggest parentheses
around inequality used as truth value". In this way, the following code will be
accepted without warnings:
if((a <= b) <= c)
something();
That's all ;)
--
Summary: Warning on if(a < b < c) and other similar codes
Product: gcc
Version: 3.4.6
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: alpt at freaknet dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29193