diff options
author | rwild <rwild@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-02-22 06:17:46 +0000 |
---|---|---|
committer | rwild <rwild@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-02-22 06:17:46 +0000 |
commit | 067d82a2aab9107b8a630df91ce2036edc8a558d (patch) | |
tree | 3f5c89f2924defd243a7584af42364ce079bb2fd /gcc | |
parent | 2dd2bcbd97b40f8e775560c6452d6263b894e142 (diff) | |
download | gcc-067d82a2aab9107b8a630df91ce2036edc8a558d.tar.gz |
gcc/:
PR c/19999
* c-typeck.c (build_binary_op): Warn about floating point
comparisons if FLOAT_TYPE_P, not only for REAL_TYPE.
gcc/cp/:
* typeck.c (build_binary_op): Warn about floating point
comparisons if FLOAT_TYPE_P, not only for REAL_TYPE.
gcc/testsuite/:
* gcc.dg/Wfloat-equal-1.c: New.
* g++.dg/warn/Wfloat-equal-1.C: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@132540 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-typeck.c | 2 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wfloat-equal-1.C | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wfloat-equal-1.c | 10 |
7 files changed, 40 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 93b1e073f3d..a7253f95ff1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-02-22 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> + + PR c/19999 + * c-typeck.c (build_binary_op): Warn about floating point + comparisons if FLOAT_TYPE_P, not only for REAL_TYPE. + 2008-02-21 Janis Johnson <janis187@us.ibm.com> PR target/34526 diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 60b0b02fc04..55b4b23a832 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -8138,7 +8138,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, case EQ_EXPR: case NE_EXPR: - if (code0 == REAL_TYPE || code1 == REAL_TYPE) + if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)) warning (OPT_Wfloat_equal, "comparing floating point with == or != is unsafe"); /* Result of comparison is always int, diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 81a243a1354..b300db04bff 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2008-02-22 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> + + PR c/19999 + * typeck.c (build_binary_op): Warn about floating point + comparisons if FLOAT_TYPE_P, not only for REAL_TYPE. + 2008-02-19 Jason Merrill <jason@redhat.com> PR c++/34950 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 9764ed369a2..eef6914da56 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -3359,7 +3359,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, case EQ_EXPR: case NE_EXPR: - if (code0 == REAL_TYPE || code1 == REAL_TYPE) + if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)) warning (OPT_Wfloat_equal, "comparing floating point with == or != is unsafe"); if ((TREE_CODE (orig_op0) == STRING_CST && !integer_zerop (op1)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 259bfbe1236..493effcce42 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-02-22 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> + + PR c/19999 + * gcc.dg/Wfloat-equal-1.c: New. + * g++.dg/warn/Wfloat-equal-1.C: New. + 2008-02-21 Michael Matz <matz@suse.de> PR target/35264 diff --git a/gcc/testsuite/g++.dg/warn/Wfloat-equal-1.C b/gcc/testsuite/g++.dg/warn/Wfloat-equal-1.C new file mode 100644 index 00000000000..36b3fa53f3f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wfloat-equal-1.C @@ -0,0 +1,10 @@ +/* PR c/19999 */ +/* { dg-do compile } */ +/* { dg-options "-Wfloat-equal" } */ + +double a, b; +_Complex double c, d; +int f(void) { return a == b; } /* { dg-warning "comparing floating point" } */ +int g(void) { return c == d; } /* { dg-warning "comparing floating point" } */ +int h(void) { return a != b; } /* { dg-warning "comparing floating point" } */ +int i(void) { return c != d; } /* { dg-warning "comparing floating point" } */ diff --git a/gcc/testsuite/gcc.dg/Wfloat-equal-1.c b/gcc/testsuite/gcc.dg/Wfloat-equal-1.c new file mode 100644 index 00000000000..36b3fa53f3f --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wfloat-equal-1.c @@ -0,0 +1,10 @@ +/* PR c/19999 */ +/* { dg-do compile } */ +/* { dg-options "-Wfloat-equal" } */ + +double a, b; +_Complex double c, d; +int f(void) { return a == b; } /* { dg-warning "comparing floating point" } */ +int g(void) { return c == d; } /* { dg-warning "comparing floating point" } */ +int h(void) { return a != b; } /* { dg-warning "comparing floating point" } */ +int i(void) { return c != d; } /* { dg-warning "comparing floating point" } */ |