This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/29193] New: Warning on if(a < b < c) and other similar codes


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]