[Bug c++/62153] warn for bool expression compared with integer different from 0/1

2014-08-19 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62153

--- Comment #6 from Marek Polacek mpolacek at gcc dot gnu.org ---
Author: mpolacek
Date: Tue Aug 19 18:50:00 2014
New Revision: 214183

URL: https://gcc.gnu.org/viewcvs?rev=214183root=gccview=rev
Log:
PR c++/62153
* doc/invoke.texi: Document -Wbool-compare.
c-family/
* c-common.c (maybe_warn_bool_compare): New function.
* c-common.h (maybe_warn_bool_compare): Declare.
* c.opt (Wbool-compare): New option.
c/
* c-typeck.c (build_binary_op): If either operand of a comparison
is a boolean expression, call maybe_warn_bool_compare.
cp/
* call.c (build_new_op_1): Remember the type of arguments for
a comparison.  If either operand of a comparison is a boolean
expression, call maybe_warn_bool_compare.
testsuite/
* c-c++-common/Wbool-compare-1.c: New test.

Added:
trunk/gcc/testsuite/c-c++-common/Wbool-compare-1.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/c-family/ChangeLog
trunk/gcc/c-family/c-common.c
trunk/gcc/c-family/c-common.h
trunk/gcc/c-family/c.opt
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-typeck.c
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/doc/invoke.texi
trunk/gcc/testsuite/ChangeLog


[Bug c++/62153] warn for bool expression compared with integer different from 0/1

2014-08-19 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62153

Marek Polacek mpolacek at gcc dot gnu.org changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #7 from Marek Polacek mpolacek at gcc dot gnu.org ---
-Wbool-compare has been added.


[Bug c++/62153] warn for bool expression compared with integer different from 0/1

2014-08-19 Thread sirl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62153

--- Comment #8 from Franz Sirl sirl at gcc dot gnu.org ---
Hmm, what about the assignment part of the merged bug 44077:

 _Bool var = 3;

Does the fix warn about this? Should I create a new bug report for this part?


[Bug c++/62153] warn for bool expression compared with integer different from 0/1

2014-08-15 Thread manu at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62153

--- Comment #1 from Manuel López-Ibáñez manu at gcc dot gnu.org ---
This should be enabled in GCC bootstrap:

https://gcc.gnu.org/ml/gcc-patches/2014-08/msg01555.html

[Bug c++/62153] warn for bool expression compared with integer different from 0/1

2014-08-15 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62153

Marek Polacek mpolacek at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2014-08-15
 CC||mpolacek at gcc dot gnu.org
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org
   Target Milestone|--- |5.0
 Ever confirmed|0   |1

--- Comment #2 from Marek Polacek mpolacek at gcc dot gnu.org ---
Sounds good.  I'll look at it, so mine for now.  But the
-Wtautological-constant-out-of-range-compare name is too long - can't we name
it just e.g. -Wbool-compare?


[Bug c++/62153] warn for bool expression compared with integer different from 0/1

2014-08-15 Thread manu at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62153

--- Comment #3 from Manuel López-Ibáñez manu at gcc dot gnu.org ---
(In reply to Marek Polacek from comment #2)
 Sounds good.  I'll look at it, so mine for now.  But the
 -Wtautological-constant-out-of-range-compare name is too long - can't we
 name it just e.g. -Wbool-compare?

I agree it is too long. Wbool-compare sounds good to me.

If you can implement it for both C and C++ and put the testcases in
testsuite/c-c++-common/, that would be great.

[Bug c++/62153] warn for bool expression compared with integer different from 0/1

2014-08-15 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62153

--- Comment #4 from Marek Polacek mpolacek at gcc dot gnu.org ---
Sure, both FEs should have it.


[Bug c++/62153] warn for bool expression compared with integer different from 0/1

2014-08-15 Thread manu at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62153

Manuel López-Ibáñez manu at gcc dot gnu.org changed:

   What|Removed |Added

 CC||sirl at gcc dot gnu.org

--- Comment #5 from Manuel López-Ibáñez manu at gcc dot gnu.org ---
*** Bug 44077 has been marked as a duplicate of this bug. ***