c-common.c (warn_logical_operator): Use tree_int_cst_equal when comparing INTEGER_CSTs.
* c-common.c (warn_logical_operator): Use tree_int_cst_equal when comparing INTEGER_CSTs. * c-c++-common/Wlogical-op-3.c: New test. From-SVN: r224853
This commit is contained in:
parent
171561ca33
commit
a68ae2e1b1
4 changed files with 33 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
2015-06-23 Marek Polacek <polacek@redhat.com>
|
||||
|
||||
* c-common.c (warn_logical_operator): Use tree_int_cst_equal
|
||||
when comparing INTEGER_CSTs.
|
||||
|
||||
2015-06-22 Pierre-Marie de Rodat <derodat@adacore.com>
|
||||
|
||||
* c-ada-spec.h (cpp_operation): Add HAS_DEPENDENT_TEMPLATE_ARGS.
|
||||
|
|
|
@ -1838,7 +1838,8 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
|
|||
}
|
||||
/* Or warn if the operands have exactly the same range, e.g.
|
||||
A > 0 && A > 0. */
|
||||
else if (low0 == low1 && high0 == high1)
|
||||
else if (tree_int_cst_equal (low0, low1)
|
||||
&& tree_int_cst_equal (high0, high1))
|
||||
{
|
||||
if (or_op)
|
||||
warning_at (location, OPT_Wlogical_op,
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2015-06-23 Marek Polacek <polacek@redhat.com>
|
||||
|
||||
* c-c++-common/Wlogical-op-3.c: New test.
|
||||
|
||||
2015-06-23 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
PR c++/66254
|
||||
|
|
22
gcc/testsuite/c-c++-common/Wlogical-op-3.c
Normal file
22
gcc/testsuite/c-c++-common/Wlogical-op-3.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* { dg-do compile } */
|
||||
/* { dg-options "-Wlogical-op" } */
|
||||
|
||||
void
|
||||
fn1 (int a)
|
||||
{
|
||||
const int x = a;
|
||||
if (x && x) {} /* { dg-warning "logical .and. of equal expressions" } */
|
||||
if (x && (int) x) {} /* { dg-warning "logical .and. of equal expressions" } */
|
||||
if ((int) x && x) {} /* { dg-warning "logical .and. of equal expressions" } */
|
||||
if ((int) x && (int) x) {} /* { dg-warning "logical .and. of equal expressions" } */
|
||||
}
|
||||
|
||||
void
|
||||
fn2 (int a)
|
||||
{
|
||||
const int x = a;
|
||||
if (x || x) {} /* { dg-warning "logical .or. of equal expressions" } */
|
||||
if (x || (int) x) {} /* { dg-warning "logical .or. of equal expressions" } */
|
||||
if ((int) x || x) {} /* { dg-warning "logical .or. of equal expressions" } */
|
||||
if ((int) x || (int) x) {} /* { dg-warning "logical .or. of equal expressions" } */
|
||||
}
|
Loading…
Add table
Reference in a new issue