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/60759] improve -Wlogical-op


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60759

Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-06-17
            Summary|-Wlogical-op should perhaps |improve -Wlogical-op
                   |warn about two-way implicit |
                   |conversions                 |
     Ever confirmed|0                           |1

--- Comment #4 from Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> ---
GCC's -Wlogical-op warns for this:

pr60759.c:6:12: warning: logical âorâ applied to non-boolean constant
[-Wlogical-op]
   return y || 3;
            ^

However, GCC does not warn when both operands are constants or neither is a
constant. I think it is clear that it should warn for the former case. The
conditions at which it should warn are the same (it warns even if the result is
used in a boolean context).

The latter case is more controversial. Moreover, in this case the context is
significant:

int a = foo(1) || foo(2);  // warn
bool a = foo(1) || foo(2);  // do NOT warn

Someone would need to check how much code will be wrongly warned and how to
minimize the amount of false positives.

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